6 gi.require_version('Gst', '1.0')
7 from gi.repository import GObject, Gst
9 def bus_call(bus, message, loop):
11 if t == Gst.MessageType.EOS:
12 sys.stdout.write("End-of-stream\n")
14 elif t == Gst.MessageType.ERROR:
15 err, debug = message.parse_error()
16 sys.stderr.write("Error: %s: %s\n" % (err, debug))
22 sys.stderr.write("usage: %s <media file or uri>\n" % args[0])
25 GObject.threads_init()
28 playbin = Gst.ElementFactory.make("playbin", None)
30 sys.stderr.write("'playbin' 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_signal_watch()
45 bus.connect ("message", bus_call, loop)
47 # start play back and listed to events
48 playbin.set_state(Gst.State.PLAYING)
55 playbin.set_state(Gst.State.NULL)
57 if __name__ == '__main__':
58 sys.exit(main(sys.argv))