3 from PyQt4
.QtCore
import SIGNAL
,SLOT
,Qt
5 from PyQt4
.QtCore
import QProcess
6 from PyQt4
.QtCore
import QStringList
10 class MProcess(QProcess
):
11 """ Mplayer process controller
15 STOPPED
, PAUSED
, PLAYING
= range(3)
16 INTERVAL
= 200 #For check timer
18 def __init__(self
, wid
= None, parent
= None):
19 super(MProcess
, self
).__init
__(parent
)
20 self
.playerState
= MProcess
.STOPPED
21 ##The current file's name.
24 ##Slider should be a QSlider or its subclass-object
25 ##self.slider will be update it isn't None
28 ##The Widget Id which used to play vedio.
31 ##Point A and Point B used to circle
35 self
.timerId
= self
.startTimer(MProcess
.INTERVAL
)
38 self
.timeLength
= None
40 self
.connect(self
, SIGNAL("readyReadStandardOutput()"),
42 self
.connect(self
, SIGNAL("readyReadStandardError()"),
45 #END def __init__(self, parent = None):
47 def setSlider(self
,slider
):
49 self
.connect(self
.slider
,SIGNAL("sliderPressed()"),
51 self
.connect(self
.slider
,SIGNAL("sliderReleased()"),
53 #END def setSlider(self,slider):
55 def sliderPressed(self
):
56 if(self
.playerState
== MProcess
.PLAYING
):
58 #END def sliderPressed(self):
60 def sliderReleased(self
):
61 self
.timePos
= self
.slider
.value()
62 self
.write("seek "+ str(self
.slider
.value()) + " 2\n")
64 #END def sliderReleased(self):
66 def setFileName(self
,fileName
):
67 self
.fileName
= fileName
69 #END def setFileName(self,fileName):
72 if(self
.fileName
== None):
76 args
= QStringList(["-slave",
78 "-wid", str(self
.wid
), self
.fileName
])
80 if(self
.state() != QProcess
.NotRunning
):
82 if(not self
.waitForFinished()):
84 self
.timeLength
= None
87 self
.playerState
= MProcess
.PLAYING
93 self
.pa
= int(self
.timePos
)/10*10;
96 self
.pb
= int(self
.timePos
) + 1;
98 def cleanPoints(self
):
102 #END def setCirclePoint(self):
104 def setVolume(self
,value
):
105 if(self
.playerState
== MProcess
.PLAYING
):
106 self
.write("volume " + str(value
) + " 1\n")
109 #END def setVolume(self,value):
111 def setupTimer(self
):
112 if(self
.timerId
== None):
113 self
.timerId
= self
.startTimer(MProcess
.INTERVAL
)
116 #END def setupTimer(self):
118 def closeTimer(self
):
119 if(self
.timerId
!= None):
120 self
.killTimer(self
.timerId
)
124 #END def closeTimer(self):
127 if(self
.playerState
== MProcess
.PAUSED
):
128 self
.playerState
= MProcess
.PLAYING
130 elif(self
.playerState
== MProcess
.PLAYING
):
132 self
.playerState
= MProcess
.PAUSED
133 else: ## if STOPPED, then return directly
136 self
.write("pause \n")
137 #END def pause(self):
141 self
.playerState
== MProcess
.STOPPED
142 self
.timeLength
= None
143 self
.write("stop \n")
146 def analyseResult(self
):
147 resStr
= self
.readAll().data()
148 if(re
.search("POSITION",resStr
)):
149 self
.timePos
= float((re
.search("\d+\.?\d",resStr
).group(0)))
150 elif(re
.search("LENGTH",resStr
)):
151 self
.timeLength
= float(re
.search("\d+\.?\d",resStr
).group(0))
152 if(self
.slider
!= None):
153 self
.slider
.setRange(0,int(self
.timeLength
)+1)
154 elif(re
.search("End of file",resStr
)):
156 self
.playerState
= MProcess
.STOPPED
157 self
.emit(SIGNAL("stopped()"))
163 if(self
.pa
== None or self
.pb
== None):
166 if( self
.pa
>= self
.pb
):
169 if(self
.timePos
> self
.pb
):
170 self
.timePos
= self
.pa
171 self
.write("seek "+ str(self
.pa
) + " 2\n")
173 #END def analyseResult(self):
175 def timerEvent(self
,event
):
176 if(event
.timerId() != self
.timerId
):
179 print self
.timePos
, " ", self
.pa
, " ", self
.pb
180 if(self
.slider
!= None and self
.timePos
!= None):
181 self
.slider
.setValue(int(self
.timePos
))
183 if(self
.playerState
== MProcess
.PAUSED
):
187 if(self
.state() == QProcess
.NotRunning
):
189 self
.playerState
= MProcess
.STOPPED
192 self
.write("get_time_pos\n")
193 if(self
.timeLength
== None):
194 self
.write("get_time_length\n")
196 self
.emit(SIGNAL("updateStatus()"))
197 #END def timerEvent(self,event):
199 #END class MProcess(QProcess):