Gstreamer based python audio player in no time
I’m learning to develop with Gstreamer 0.10 framework, which natively comes with Python binding, which is rare enough to notice for a project.
So, starting an audio player is quite simple:
- create a player from the GstElement factory
- give your file uri to the player and set it to play
- start a loop (i used gobject here, but it should work with gtk.main() or a while-true loop)
Here is the code:
import pygst pygst.require('0.10') import gst import gobject, sys def play_uri(uri): " play an uri like file:///home/foo/bar.mp3 " mainloop = gobject.MainLoop() player = gst.element_factory_make("playbin", "player") print 'Playing:', uri player.set_property('uri', uri) player.set_state(gst.STATE_PLAYING) mainloop.run()
Ok, this is a start, now i need to:
- get status information
- seek + / -
- play/pause/stop
- manage a playing queue
- manage video playing
So things will be a bit more complicated in a moment ;)