emit end-of-stream in end of track callback, pull for gstreamer end-of-stream messages and send end of track mpd command

This commit is contained in:
Johannes Knutsen 2010-08-10 13:24:58 +02:00
parent e831866a68
commit d509c12c1e

View File

@ -196,6 +196,21 @@ class LibspotifyTranslator(object):
tracks=[cls.to_mopidy_track(t) for t in spotify_playlist],
)
class GstreamerMessageBusProcess(threading.Thread):
def __init__(self, core_queue, pipeline):
super(GstreamerMessageBusProcess, self).__init__()
self.core_queue = core_queue
self.bus = pipeline.get_bus()
def run(self):
while True:
message = self.bus.pop()
if message is not None:
logger.debug('Got Gstreamer message of type: %s' % message.type)
if message is not None and (
message.type == gst.MESSAGE_EOS
or message.type == gst.MESSAGE_ERROR):
self.core_queue.put({'command': 'end_of_track'})
class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
cache_location = os.path.expanduser(settings.SPOTIFY_LIB_CACHE)
@ -229,6 +244,9 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
gst.element_link_many(self.gsrc, self.gsink)
message_process = GstreamerMessageBusProcess(self.core_queue, self.gstreamer_pipeline)
message_process.start()
def run(self):
self.connect()
@ -292,8 +310,9 @@ class LibspotifySessionManager(SpotifySessionManager, threading.Thread):
def end_of_track(self, session):
"""Callback used by pyspotify"""
logger.debug('End of track')
self.core_queue.put({'command': 'end_of_track'})
logger.debug('End of track.')
self.gsrc.emit('end-of-stream')
logger.debug('End of stream sent to gstreamer.')
def search(self, query, connection):
"""Search method used by Mopidy backend"""