Howto create a command line music player in Python
import gst, gobject, sys, gconf
mainloop = gobject.MainLoop()
# 1. We need to get the default audio sink, which is
# basically the output we are going to use in the
# GStreamer backend
# Get the GConf object
conf = gconf.client_get_default ()
# Get the key holding the audio sink
sink = conf.get ("/system/gstreamer/%d.%d/default/audiosink" % gst.gst_version[:-1])
# Check if the property actually exists
if sink is None:
print >> sys.err, "Error retrieving system audio ouput driver."
print >> sys.err, "Defaultign to OSS driver."
sink = "osssink"
else:
# Get the value in the key
sink = sink.get_string ()
# 2. Create the GStreamer object needed to play the music
bin = gst.parse_launch ("filesrc ! decodebin ! %s" % (sink,))
# 3. Get the file source object and set its location
src = bin.get_list ()[0]
src.set_property ("location", sys.argv[1])
# 4. Create the loop and hook up the end
bin.connect ("eos", mainloop.quit)
# 5. Start playing
bin.set_state (gst.STATE_PLAYING)
gobject.idle_add (bin.iterate)
mainloop.run()
Back to top