MCPcopy Create free account
hub / github.com/GStreamer/gst-python / GstPlayer

Class GstPlayer

old_examples/remuxer.py:20–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18gtk.gdk.threads_init()
19
20class GstPlayer:
21 def __init__(self, videowidget):
22 self.playing = False
23 self.player = gst.element_factory_make("playbin", "player")
24 self.videowidget = videowidget
25
26 bus = self.player.get_bus()
27 bus.enable_sync_message_emission()
28 bus.add_signal_watch()
29 bus.connect('sync-message::element', self.on_sync_message)
30 bus.connect('message', self.on_message)
31
32 def on_sync_message(self, bus, message):
33 if message.structure is None:
34 return
35 if message.structure.get_name() == 'prepare-xwindow-id':
36 # Sync with the X server before giving the X-id to the sink
37 gtk.gdk.threads_enter()
38 gtk.gdk.display_get_default().sync()
39 self.videowidget.set_sink(message.src)
40 message.src.set_property('force-aspect-ratio', True)
41 gtk.gdk.threads_leave()
42
43 def on_message(self, bus, message):
44 t = message.type
45 if t == gst.MESSAGE_ERROR:
46 err, debug = message.parse_error()
47 print "Error: %s" % err, debug
48 if self.on_eos:
49 self.on_eos()
50 self.playing = False
51 elif t == gst.MESSAGE_EOS:
52 if self.on_eos:
53 self.on_eos()
54 self.playing = False
55
56 def set_location(self, location):
57 self.player.set_state(gst.STATE_NULL)
58 self.player.set_property('uri', location)
59
60 def get_location(self):
61 return self.player.get_property('uri')
62
63 def query_position(self):
64 "Returns a (position, duration) tuple"
65 try:
66 position, format = self.player.query_position(gst.FORMAT_TIME)
67 except:
68 position = gst.CLOCK_TIME_NONE
69
70 try:
71 duration, format = self.player.query_duration(gst.FORMAT_TIME)
72 except:
73 duration = gst.CLOCK_TIME_NONE
74
75 return (position, duration)
76
77 def seek(self, location):

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected