Skip to content

Instantly share code, notes, and snippets.

@josch
Created September 9, 2009 18:50
Show Gist options
  • Save josch/183967 to your computer and use it in GitHub Desktop.
Save josch/183967 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pygst
pygst.require('0.10')
import os
import gst
from gobject import timeout_add, MainLoop
mainloop = MainLoop()
pipeline = gst.element_factory_make('playbin')
def on_eos(gst_bus, message):
timeout_add(0, get_tag)
def on_error(gst_bus, message):
timeout_add(0, get_tag)
def on_tag(gst_bus, message):
tags = message.parse_tag()
for key in tags.keys():
print tags[key]
timeout_add(0, get_tag)
gst_bus = pipeline.get_bus()
gst_bus.add_signal_watch()
gst_bus.connect('message::eos', on_eos)
gst_bus.connect('message::error', on_error)
gst_bus.connect('message::tag', on_tag)
def files():
for root, dirs, files in os.walk("/home/josch/Music/"):
for name in files:
yield os.path.join(root, name)
f = files()
def get_tag():
pipeline.set_state(gst.STATE_NULL)
try:
track = f.next()
except StopIteration:
mainloop.quit()
else:
print "--", track
pipeline.set_property('uri','file://'+track)
pipeline.set_state(gst.STATE_PLAYING)
timeout_add(0, get_tag)
mainloop.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment