12 def bus_call(bus, message, loop):
14 if t == gst.MESSAGE_EOS:
15 sys.stout.write("End-of-stream\n")
17 elif t == gst.MESSAGE_ERROR:
18 err, debug = message.parse_error()
19 sys.stderr.write("Error: %s: %s\n" % err, debug)
25 sys.stderr.write("usage: %s <media file or uri>\n" % args[0])
28 playbin = gst.element_factory_make("playbin2", None)
30 sys.stderr.write("'playbin2' gstreamer plugin missing\n")
33 # take the commandline argument and ensure that it is a uri
34 if gst.uri_is_valid(args[1]):
37 uri = gst.filename_to_uri(args[1])
38 playbin.set_property('uri', uri)
40 # create and event loop and feed gstreamer bus mesages to it
41 loop = gobject.MainLoop()
43 bus = playbin.get_bus()
44 bus.add_watch(bus_call, loop)
46 # start play back and listed to events
47 playbin.set_state(gst.STATE_PLAYING)
51 playbin.set_state(gst.STATE_NULL)
53 if __name__ == '__main__':
54 sys.exit(main(sys.argv))