Add timestamp and duration to all spotify buffers.
This fixes the issue where pausing playback would show the time of the last timestamped buffer instead of the current time. We also make sure to reset the time when we start a new track. This was done by overriding the play method on the session manager as it is also used for pausing, resuming and stopping. Ideally this should probably be reworked to avoid the gst import in mopidy.backends.spotify.playback, but for now this should do.
This commit is contained in:
parent
ea2f2d74b5
commit
8a0c48e61e
@ -1,5 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pygst
|
||||
pygst.require('0.10')
|
||||
import gst
|
||||
|
||||
import logging
|
||||
import functools
|
||||
|
||||
@ -35,6 +39,7 @@ class SpotifyPlaybackProvider(base.BasePlaybackProvider):
|
||||
self.backend.spotify.session.load(
|
||||
Link.from_string(track.uri).as_track())
|
||||
self.backend.spotify.session.play(1)
|
||||
self.backend.spotify.buffer_timestamp = 0
|
||||
|
||||
self.audio.prepare_change()
|
||||
self.audio.set_appsrc(
|
||||
@ -54,5 +59,5 @@ class SpotifyPlaybackProvider(base.BasePlaybackProvider):
|
||||
|
||||
def on_seek_data(self, time_position):
|
||||
logger.debug('playback.on_seek_data(%d) called', time_position)
|
||||
self.backend.spotify.next_buffer_timestamp = time_position
|
||||
self.backend.spotify.buffer_timestamp = time_position * gst.MSECOND
|
||||
self.backend.spotify.session.seek(time_position)
|
||||
|
||||
@ -46,7 +46,7 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager):
|
||||
self.backend_ref = backend_ref
|
||||
|
||||
self.connected = threading.Event()
|
||||
self.next_buffer_timestamp = None
|
||||
self.buffer_timestamp = 0
|
||||
|
||||
self.container_manager = None
|
||||
self.playlist_manager = None
|
||||
@ -121,11 +121,13 @@ class SpotifySessionManager(process.BaseThread, PyspotifySessionManager):
|
||||
'sample_rate': sample_rate,
|
||||
'channels': channels,
|
||||
}
|
||||
|
||||
buffer_ = gst.Buffer(bytes(frames))
|
||||
buffer_.set_caps(gst.caps_from_string(capabilites))
|
||||
if self.next_buffer_timestamp is not None:
|
||||
buffer_.timestamp = self.next_buffer_timestamp * gst.MSECOND
|
||||
self.next_buffer_timestamp = None
|
||||
buffer_.timestamp = self.buffer_timestamp
|
||||
buffer_.duration = num_frames * gst.SECOND / sample_rate
|
||||
|
||||
self.buffer_timestamp += buffer_.duration
|
||||
|
||||
if self.audio.emit_data(buffer_).get():
|
||||
return num_frames
|
||||
|
||||
Loading…
Reference in New Issue
Block a user