[英]Unable to seek video in PyQt4
I wrote a simple video player using Phonon in PyQt4. 我在PyQt4中使用Phonon编写了一个简单的视频播放器。 The videos are playing fine. 视频播放正常。 But I am unable to seek the video to given position. 但是我无法将视频定位到指定位置。 This the code I've written: 这是我编写的代码:
#!/usr/bin/python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.phonon import Phonon
import sys
class VideoPlayer(QWidget):
def __init__(self, address, parent = None):
self.address = address
QWidget.__init__(self)
self.player = Phonon.VideoPlayer(Phonon.VideoCategory, self)
self.player.load(Phonon.MediaSource(self.address))
window = QHBoxLayout(self)
window.addWidget(self.player)
self.setWindowTitle("Simple Video Player")
self.player.play()
self.player.seek(10240)
app = QApplication(sys.argv)
vp = VideoPlayer(sys.argv[1])
vp.show()
app.exec_()
All I am trying to do is to start and stop a video at given positions. 我要做的就是在给定的位置开始和停止视频。
Thanks in advance. 提前致谢。
It is not possible to seek to a position in a media source whilst it is still loading. 当媒体源仍在加载时,无法在媒体源中寻找位置。
So connect a handler to the media object's stateChanged signal, and wait until it's state changes to PlayingState before attempting to seek. 因此,将处理程序连接到媒体对象的stateChanged信号,并等待其状态更改为PlayingState之后再尝试查找。
self.player.mediaObject().stateChanged.connect(self.handleStateChanged)
...
def handleStateChanged(self, newstate, oldstate):
if newstate == Phonon.PlayingState:
self.player.seek(10240)
Some media isn't easily seekable by Phonon. 声子不容易找到某些媒体。 The documentation says 该文件说
Note that the backend is free to ignore the seek request if the media source isn't seekable; 注意,如果媒体源不可搜索,则后端可以随意忽略搜索请求。 you can check this by asking the media object of the VideoPlayer. 您可以通过询问VideoPlayer的媒体对象来进行检查。
player->mediaObject()->isSeekable();
My guess is that your video isn't seekable. 我的猜测是您的视频无法搜索。
What media are you using? 您正在使用什么媒体? Things like streaming video (for example), generally aren't seekable. 例如,流媒体视频之类的东西通常是不受欢迎的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.