0

I'd like to make a simple music player using the GI library, including the recent Gstreamer1.0. The interface is just comprised of 2 buttons (play/pause) and a scale to seek the current playback time:

here's a simple screen of the interface

I pretty much well understood the pipeline and element stuff, I also figured out how to seek to a wanted playback time (when the user changes the value of the scale), but i wonder what's the best way to automatically update the slider/scale when the file is playing. One way, implemented here using the old API, is to use a timer that periodically reads the current player position and updates the slider's position:

Glib.timeout_add(100, update_slider_callback)

I don't find it very elegant, is there any better way to do this using the new GI API?

EDIT: for anyone curious, I implemented it here

Hadrien Titeux
  • 450
  • 2
  • 11

1 Answers1

1

That's roughly how this is implemented in pitivi at least, which is a good reference for gst / python code.

Here is the exact location :

https://git.gnome.org/browse/pitivi/tree/pitivi/utils/pipeline.py#n390

The position querying is encapsulated in a custom pipeline subclass but the code is similar.

You should have a look around this utils folder btw, plenty of good stuff in there :)

As for elegance, querying the position repetitively in the main thread doesn't seem such a hack to me.

Mathieu_Du
  • 787
  • 4
  • 10
  • Okdac! I just didn't know much about the conventions in Gst and such. Sympa d'avoir une reponse d'un dev pitivi en personne! Super taff que vous faites! i'll take a look at the pitivi utils, but i'm afraid it might be a bit too hardcore for a beginner like me :P – Hadrien Titeux Dec 29 '14 at 11:49
  • Hehe merci :) Regarding the utils, the SimplePipeline and AssetPipeline subclass can be useful for you, if you take the code you can register to the "position" signal and not have anything more to do :) – Mathieu_Du Dec 29 '14 at 19:47
  • Just pointing that g_idle_add would be less intrusive with the GST loop than a timeout, but just guessing... – alvaropg Dec 31 '14 at 14:14
  • Not the case, will kill the CPU softly. – Mathieu_Du Dec 31 '14 at 20:01