rind: Respond to the playbin's about-to-finish signal

We use this to load the next track without changing the pipeline state,
which should give us smoother audio switching.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2019-03-21 14:14:43 -04:00
parent c447c9e2b7
commit b9035abf8a
2 changed files with 13 additions and 3 deletions

View File

@ -31,8 +31,14 @@ class EmmentalAudio:
NextButton.connect( "clicked", self.next)
ProgScale.connect("change-value", self.seek)
self.playbin.connect("about-to-finish", self.about_to_finish)
self.timeout = GLib.timeout_add(100, self.update_progress)
def about_to_finish(self, playbin):
track = curds.PlaylistManager.next()
if track:
self.playbin.set_property("uri", f"file://{track.path}")
def duration(self):
(res, cur) = self.playbin.query_duration(Gst.Format.TIME)
return cur / Gst.SECOND if res == True else 0.0
@ -44,9 +50,7 @@ class EmmentalAudio:
self.playbin.set_state(Gst.State.PLAYING)
def next(self, *args):
track = curds.PlaylistManager.next()
if track != None:
self.load(track)
self.load(curds.PlaylistManager.next())
def on_message(self, bus, message):
if message.type == Gst.MessageType.STATE_CHANGED:

View File

@ -139,3 +139,9 @@ class TestGst(unittest.TestCase):
self.main_loop()
self.assertTrue( gst.PauseButton.is_visible())
self.assertFalse(gst.PlayButton.is_visible())
track = curds.PlaylistManager.track
self.audio.seek(value=99)
time.sleep(0.1)
self.main_loop()
self.assertNotEqual(curds.PlaylistManager.track, track)