Attachment 'qt3-mplayerwidget.py'
Download 1 #!/usr/bin/env python
2 # See http://www.mplayerhq.hu/DOCS/tech/slave.txt
3 # and mplayer -input cmdlist
4 from qt import *
5 import os, atexit
6
7
8 class MPlayerWidget(QWidget):
9
10 CMD = "mplayer -slave -quiet -noconsolecontrols -nomouseinput -vo %(VO)s -ao %(AO)s -wid %(WID)s %(FILENAME)r"
11
12
13 CFG = dict(
14 AO = "alsa",
15 VO = "xv" #VO = "x11"
16 )
17
18
19 def __init__(self, parent=None):
20 QWidget.__init__(self, parent)
21 self.process = None
22 self.layout = QVBoxLayout(self)
23
24 self.view = QLabel(self)
25 self.layout.addWidget(self.view)
26
27 self.controls = QHBoxLayout(self)
28 self.layout.addLayout(self.controls)
29
30 self.pauseButton = QToolButton(self)
31 self.pauseButton.setMaximumHeight(32)
32 self.pauseButton.setText("&Pause")
33 self.pauseButton.setAutoRaise(True)
34 self.pauseButton.setToggleButton(True)
35 self.connect(self.pauseButton, SIGNAL("clicked()"), self.toggle_pause)
36 self.controls.addWidget(self.pauseButton)
37
38 self.muteButton = QToolButton(self)
39 self.muteButton.setText("&Mute")
40 self.muteButton.setAutoRaise(True)
41 self.muteButton.setToggleButton(True)
42 self.connect(self.muteButton, SIGNAL("clicked()"), self.toggle_mute)
43 self.controls.addWidget(self.muteButton)
44
45 self.quitButton = QToolButton(self)
46 self.quitButton.setText("&Close")
47 self.quitButton.setAutoRaise(True)
48 self.connect(self.quitButton, SIGNAL("clicked()"), self.exit)
49 self.controls.addWidget(self.quitButton)
50
51
52 def start(self, filename):
53 self.pause_flag = False
54 self.fullscreen_flag = False
55 self.show()
56 self.view.setText("Loading %s..." % filename)
57 qApp.processEvents()
58
59 self.CFG["WID"] = self.view.winId()
60 self.CFG["FILENAME"] = filename
61 self.process = os.popen(self.CMD % self.CFG, "w", 1)
62
63 atexit.register(self.exit)
64
65
66
67 def play(self, filename):
68 if self.process:
69 self("quit")
70 self.process.close()
71
72 self.start(filename)
73
74
75 def osd(self, msg):
76 self("osd_show_text %s" % msg)
77
78
79 def exit(self):
80 if self.process:
81 self("pause")
82 self("quit 0")
83 self.process.close()
84 self.process = None
85 self.close()
86
87
88 def __call__(self, cmd):
89 if self.process:
90 print "*", cmd
91 self.process.write("\n%s\n" % cmd)
92
93
94 def __del__(self):
95 self.exit()
96
97
98 def load(self, url):
99 self.CFG["FILENAME"] = url
100 self("loadfile %s" % url)
101
102
103 def toggle_mute(self):
104 self("mute")
105
106
107 def toggle_pause(self):
108 if not self.pause_flag:
109 self.osd("Paused")
110 self("pause")
111 self.pause_flag = not self.pause_flag
112
113
114 def pause(self):
115 if not self.pause_flag:
116 self.toggle_pause()
117
118
119 def unpause(self):
120 if self.pause_flag:
121 self.toggle_pause()
122
123
124 def fullscreen(self):
125 if not self.fullscreen_flag:
126 self("vo_fullscreen")
127 self.fullscreen_flag = True
128
129
130 def windowed(self):
131 if self.fullscreen_flag:
132 self("vo_fullscreen")
133 self.fullscreen_flag = False
134
135
136
137 if __name__ == "__main__":
138 import sys
139 if len(sys.argv) != 2:
140 print "Usage: %s FILENAME" % sys.argv[0]
141 sys.exit()
142 app = QApplication(sys.argv)
143 win = MPlayerWidget()
144 win.resize(320, 240)
145 app.setMainWidget(win)
146 win.play(sys.argv[1])
147 app.exec_loop()
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.