-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathplaybin-example-cliplayer.py
More file actions
executable file
·47 lines (40 loc) · 1.46 KB
/
playbin-example-cliplayer.py
File metadata and controls
executable file
·47 lines (40 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import sys, os, time, thread
import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst, GLib, GObject
class CLI_Main(object):
def __init__(self):
self.player = Gst.ElementFactory.make("playbin", "player")
fakesink = Gst.ElementFactory.make("fakesink", "fakesink")
self.player.set_property("video-sink", fakesink)
bus = self.player.get_bus()
bus.add_signal_watch()
bus.connect("message", self.on_message)
def on_message(self, bus, message):
t = message.type
if t == Gst.MessageType.EOS:
self.player.set_state(Gst.State.NULL)
self.playmode = False
elif t == Gst.MessageType.ERROR:
self.player.set_state(Gst.State.NULL)
err, debug = message.parse_error()
print("Error: %s" % err, debug)
self.playmode = False
def start(self):
for filepath in sys.argv[1:]:
if os.path.isfile(filepath):
filepath = os.path.realpath(filepath)
self.playmode = True
self.player.set_property("uri", "file://" + filepath)
self.player.set_state(Gst.State.PLAYING)
while self.playmode:
time.sleep(1)
time.sleep(1)
loop.quit()
GObject.threads_init()
Gst.init(None)
mainclass = CLI_Main()
thread.start_new_thread(mainclass.start, ())
loop = GLib.MainLoop()
loop.run()