rind: Set Title and Artist from gstreamer tags
This helps us prepare for the about-to-finish signal by setting this information when gstreamer starts playing the next track. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
bd37bfd3f7
commit
a48a2ada76
|
@ -104,7 +104,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="subtitle">
|
||||
<object class="GtkLabel" id="artist">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes"><big>The Cheesy Music Player</big></property>
|
||||
|
|
17
rind/gst.py
17
rind/gst.py
|
@ -15,7 +15,7 @@ PauseButton = gtk.Builder.get_object("pause_button")
|
|||
PlayButton = gtk.Builder.get_object("play_button")
|
||||
Position = gtk.Builder.get_object("position")
|
||||
ProgScale = gtk.Builder.get_object("progress_scale")
|
||||
Subtitle = gtk.Builder.get_object("subtitle")
|
||||
Artist = gtk.Builder.get_object("artist")
|
||||
Title = gtk.Builder.get_object("title")
|
||||
|
||||
class EmmentalAudio:
|
||||
|
@ -42,8 +42,6 @@ class EmmentalAudio:
|
|||
self.playbin.set_state(Gst.State.READY)
|
||||
self.playbin.set_property("uri", f"file://{track.path}")
|
||||
self.playbin.set_state(Gst.State.PLAYING)
|
||||
Title.set_markup(f"<big>{GLib.markup_escape_text(track['title'])}</big>")
|
||||
Subtitle.set_markup(f"<big>by {GLib.markup_escape_text(track['artist'])}</big>")
|
||||
|
||||
def next(self, *args):
|
||||
track = curds.PlaylistManager.next()
|
||||
|
@ -55,9 +53,22 @@ class EmmentalAudio:
|
|||
(old, new, pending) = message.parse_state_changed()
|
||||
PlayButton.set_visible( new != Gst.State.PLAYING)
|
||||
PauseButton.set_visible(new == Gst.State.PLAYING)
|
||||
if new == Gst.State.READY:
|
||||
Title.set_markup("<big>Emmental</big>")
|
||||
Artist.set_markup("<big>The Cheesy Music Player</big>")
|
||||
curds.Notify.notify("state-changed", new)
|
||||
elif message.type == Gst.MessageType.STREAM_START:
|
||||
curds.Notify.notify("duration-changed", self.duration())
|
||||
elif message.type == Gst.MessageType.TAG:
|
||||
taglist = message.parse_tag()
|
||||
for i in range(taglist.n_tags()):
|
||||
name = taglist.nth_tag_name(i)
|
||||
if name == "artist":
|
||||
artist = GLib.markup_escape_text(taglist.get_string(name)[1])
|
||||
Artist.set_markup(f"<big>by {artist}</big>")
|
||||
elif name == "title":
|
||||
title = GLib.markup_escape_text(taglist.get_string(name)[1])
|
||||
Title.set_markup(f"<big>{title}</big>")
|
||||
return True
|
||||
|
||||
def pause(self, *args):
|
||||
|
|
|
@ -35,12 +35,17 @@ class TestGst(unittest.TestCase):
|
|||
self.assertIsInstance(audio.bus, Gst.Bus)
|
||||
|
||||
self.assertIsInstance(gst.Adjustment, Gtk.Adjustment)
|
||||
self.assertIsInstance(gst.Artist, Gtk.Label)
|
||||
self.assertIsInstance(gst.Duration, Gtk.Label)
|
||||
self.assertIsInstance(gst.NextButton, Gtk.Button)
|
||||
self.assertIsInstance(gst.PauseButton, Gtk.Button)
|
||||
self.assertIsInstance(gst.PlayButton, Gtk.Button)
|
||||
self.assertIsInstance(gst.Position, Gtk.Label)
|
||||
self.assertIsInstance(gst.ProgScale, Gtk.Scale)
|
||||
self.assertIsInstance(gst.Title, Gtk.Label)
|
||||
|
||||
self.assertEqual(gst.Title.get_text(), "Emmental")
|
||||
self.assertEqual(gst.Artist.get_text(), "The Cheesy Music Player")
|
||||
|
||||
self.assertFalse(gst.PauseButton.is_visible())
|
||||
self.assertTrue( gst.PlayButton.is_visible())
|
||||
|
@ -69,6 +74,13 @@ class TestGst(unittest.TestCase):
|
|||
self.assertEqual(audio.duration(), 0)
|
||||
self.assertEqual(audio.progress(), 0)
|
||||
|
||||
audio.playbin.set_state(Gst.State.READY)
|
||||
time.sleep(0.1)
|
||||
self.main_loop()
|
||||
GLib.source_remove(audio.timeout)
|
||||
gst.Position.set_text("00:00")
|
||||
gst.Duration.set_text("-00:00")
|
||||
|
||||
def on_state_changed(self, state):
|
||||
self.state = state
|
||||
|
||||
|
@ -79,19 +91,18 @@ class TestGst(unittest.TestCase):
|
|||
audio = gst.EmmentalAudio()
|
||||
track = curds.Track.lookup(os.path.join(test_album, "10 - Test Track 10.ogg"))
|
||||
|
||||
self.main_loop()
|
||||
self.state = None
|
||||
self.duration = None
|
||||
audio.load(track)
|
||||
while self.state == None or self.duration == None:
|
||||
|
||||
while self.state != Gst.State.PLAYING:
|
||||
time.sleep(0.1)
|
||||
self.main_loop()
|
||||
|
||||
self.assertEqual(self.state, Gst.State.PAUSED)
|
||||
self.assertEqual(gst.Title.get_text(), track['title'])
|
||||
self.assertEqual(gst.Subtitle.get_text(), "by " + track["artist"])
|
||||
self.assertEqual(self.state, Gst.State.PLAYING)
|
||||
self.assertEqual(gst.Title.get_text(), track['title'])
|
||||
self.assertEqual(gst.Artist.get_text(), "by " + track["artist"])
|
||||
|
||||
self.assertEqual(audio.progress(), 0)
|
||||
self.assertEqual(audio.position(), 0)
|
||||
self.assertGreater(audio.progress(), 0)
|
||||
self.assertGreater(audio.position(), 0)
|
||||
self.assertEqual(gst.Position.get_text(), "00:00")
|
||||
|
||||
while self.state != Gst.State.PLAYING:
|
||||
|
@ -149,6 +160,9 @@ class TestGst(unittest.TestCase):
|
|||
while self.state != Gst.State.PAUSED:
|
||||
self.main_loop()
|
||||
|
||||
audio.playbin.set_state(Gst.State.READY)
|
||||
time.sleep(0.1)
|
||||
self.main_loop()
|
||||
GLib.source_remove(audio.timeout)
|
||||
gst.Position.set_text("00:00")
|
||||
gst.Duration.set_text("-00:00")
|
||||
|
|
Loading…
Reference in New Issue