Pyqt4 如何更新QtGui.QSlider';视频播放时,s的位置?

Pyqt4 如何更新QtGui.QSlider';视频播放时,s的位置?,pyqt4,phonon,Pyqt4,Phonon,我目前正在使用PyQt4开发视频播放器GUI,并使用QtGui.QSlider控制视频流的进度。我想知道在播放视频时如何更改滑块的值 import sys, os import xml.etree.ElementTree as ET from xml.dom import minidom from PyQt4 import QtCore, QtGui, uic from PyQt4.phonon import Phonon class vidplayer(QtGui.QWidget): d

我目前正在使用PyQt4开发视频播放器GUI,并使用QtGui.QSlider控制视频流的进度。我想知道在播放视频时如何更改滑块的值

import sys, os
import xml.etree.ElementTree as ET
from xml.dom import minidom
from PyQt4 import QtCore, QtGui, uic
from PyQt4.phonon import Phonon

class vidplayer(QtGui.QWidget):


def __init__(self,url,xml_url,parent = None):
    self.url = url
    super(vidplayer,self).__init__()
    self.initUI()
    self.getElm_from_XML(xml_url);


def printXMLInfo(self):
    itemlist = self.doc.getElementsByTagName('object')
    for item in itemlist:
        print ("frame-span:"+str(item.attributes['framespan'].value)+
        " Event tag: "+ str(item.attributes['name'].value));
    print(len(itemlist))


def getElm_from_XML(self,xml_url):
    self.doc = minidom.parse(xml_url)
    self.clipList = self.doc.getElementsByTagName('object');
    print("Reading XML done...\n Have read %s elements.\n" %(len(self.clipList)))


def initUI(self):
    ## create widgets
    # phonon video player and media
    self.vp = Phonon.VideoPlayer()
    media = Phonon.MediaSource(self.url)

    # layout components (boxes)
    self.vbox_play = QtGui.QVBoxLayout()
    self.hbox_ctrl_vid = QtGui.QHBoxLayout()
    self.hbox_ctrl_dec = QtGui.QHBoxLayout()
    self.hbox = QtGui.QHBoxLayout()
    self.vbox_control = QtGui.QVBoxLayout()

    # bottons to control
    self.btn_go_prev = QtGui.QPushButton("|<")
    self.btn_go_next = QtGui.QPushButton(">|")
    self.btn_play = QtGui.QPushButton("Play(Pause)")
    self.btn_accept = QtGui.QPushButton("Accept")
    self.btn_reject = QtGui.QPushButton("Reject")

    # slider to interact with videoplayer
    self.sld = QtGui.QSlider(QtCore.Qt.Horizontal,self)
    #self.sld = Phonon.SeekSlider(self)

    ## layout components setup
    self.vbox_control.addStretch(1)
    self.hbox_ctrl_vid.addStretch(1)
    self.hbox_ctrl_dec.addStretch(1)
    self.vbox_play.addStretch(1)
    self.hbox.addStretch(1)
    self.vbox_control.setDirection(QtGui.QBoxLayout.BottomToTop)
    self.vbox_play.setDirection(QtGui.QBoxLayout.BottomToTop)


    ## widgets inits
    self.vp.load(media)
    self.vp.play()

    self.sld.setFocusPolicy(QtCore.Qt.NoFocus)
    self.sld.setRange(1,1000)


    ## widgets assignment
    self.hbox_ctrl_vid.addWidget(self.btn_go_prev)
    self.hbox_ctrl_vid.addWidget(self.btn_play)
    self.hbox_ctrl_vid.addWidget(self.btn_go_next)
    self.hbox_ctrl_dec.addWidget(self.btn_accept)
    self.hbox_ctrl_dec.addWidget(self.btn_reject)

    self.vbox_play.addWidget(self.vp)
    self.vbox_play.addWidget(self.sld)

    self.vbox_control.addLayout(self.hbox_ctrl_dec)
    self.vbox_control.addLayout(self.hbox_ctrl_vid)

    self.hbox.addLayout(self.vbox_play)
    self.hbox.addLayout(self.vbox_control)


    ## main setup and display
    self.setLayout(self.hbox)
    self.setGeometry(300,300,600,400)
    self.setWindowTitle('CCNY_SRI TRECVid iSED UI')
    self.setWindowIcon(QtGui.QIcon('./icon.png'))
    self.show()


    ## connection set up
    self.sld.valueChanged[int].connect(self.sld_changeValue)
    self.vp.finished.connect(self.onReachingFinish)
    self.btn_play.clicked.connect(self.onClicked_play)
    self.btn_go_next.clicked.connect(self.onClicked_nextClip)
    self.btn_go_prev.clicked.connect(self.onClicked_prevClip)


###################### callable functions ##################
def sld_changeValue(self,value):
    totalT = self.vp.totalTime()
    print totalT
    newT = totalT*value/1000
    self.vp.seek(newT)

def onClicked_play(self):
    # BUG: sth wrong with boundary
    if self.vp.isPaused():
        self.vp.play()
        print("resume play")
    elif self.vp.isPlaying():
        self.vp.pause()
        print("pause at",self.sld.value())
    elif self.sld.value()<1000:
        self.vp.play()

def onClicked_nextClip(self):
    print("go next")

def onClicked_prevClip(self):
    print("go prev")

def onClicked_acc(self):
    print("accepted")

def onClicked_rej(self):
    print("rejected")

def onReachingFinish(self):
    self.vp.pause()
    self.vp.stop()


def main():
    app = QtGui.QApplication(sys.argv)
    window = vidplayer(sys.argv[1],sys.argv[2])
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()
导入系统,操作系统 将xml.etree.ElementTree作为ET导入 从xml.dom导入minidom 从PyQt4导入QtCore、QtGui、uic 从PyQt4.声子导入声子 类vidplayer(QtGui.QWidget): 定义初始化(self,url,xml\u url,parent=None): self.url=url 超级(视频播放器,自我)。\uuu初始化 self.initUI() self.getElm_from_XML(XML_url); def printXMLInfo(自): itemlist=self.doc.getElementsByTagName('object') 对于itemlist中的项目: 打印(“帧跨度:”+str(item.attributes['framespan'].value)+ 事件标记:“+str(item.attributes['name'].value)); 打印(len(项目列表)) def getElm_from_XML(self,XML_url): self.doc=minidom.parse(xml\u url) self.clipList=self.doc.getElementsByTagName('object'); 打印(“读取XML已完成…\n已读取%s个元素。\n”%(len(self.clipList))) def initUI(self): ##创建小部件 #声子视频播放器与媒体 self.vp=Phonon.VideoPlayer() media=Phonon.MediaSource(self.url) #布局组件(框) self.vbox_play=QtGui.QVBoxLayout() self.hbox\u ctrl\u vid=QtGui.QHBoxLayout() self.hbox\u ctrl\u dec=QtGui.QHBoxLayout() self.hbox=QtGui.QHBoxLayout() self.vbox_control=QtGui.QVBoxLayout() #要控制的僵尸 self.btn_go_prev=QtGui.QPushButton(“| |”) self.btn_play=QtGui.QPushButton(“播放(暂停)”) self.btn_accept=QtGui.QPushButton(“接受”) self.btn_reject=QtGui.QPushButton(“拒绝”) #滑块与视频播放器交互 self.sld=QtGui.QSlider(QtCore.Qt.Horizontal,self) #self.sld=声子SeekSlider(self) ##布局组件设置 self.vbox\u控件.addStretch(1) self.hbox\u ctrl\u vid.addStretch(1) self.hbox\u ctrl\u dec.addStretch(1) self.vbox\u play.addStretch(1) self.hbox.addStretch(1) self.vbox_control.setDirection(QtGui.QBoxLayout.bottomtoop) self.vbox\u play.setDirection(QtGui.QBoxLayout.bottomtoop) ##控件初始化 自我副总裁加载(媒体) self.vp.play() self.sld.setFocusPolicy(QtCore.Qt.NoFocus) self.sld.setRange(11000) ##小部件分配 self.hbox\u ctrl\u vid.addWidget(self.btn\u go\u prev) self.hbox\u ctrl\u vid.addWidget(self.btn\u play) self.hbox\u ctrl\u vid.addWidget(self.btn\u go\u next) self.hbox\u ctrl\u dec.addWidget(self.btn\u accept) self.hbox\u ctrl\u dec.addWidget(self.btn\u拒绝) self.vbox\u play.addWidget(self.vp) self.vbox\u play.addWidget(self.sld) self.vbox\u control.addLayout(self.hbox\u ctrl\u dec) self.vbox\u control.addLayout(self.hbox\u ctrl\u vid) self.hbox.addLayout(self.vbox\u播放) self.hbox.addLayout(self.vbox\u控件) ##主设置和显示 self.setLayout(self.hbox) 自设置几何体(300600400) self.setWindowTitle('CCNY_SRI TRECVid-iSED UI') self.setWindowIcon(QtGui.QIcon('./icon.png')) self.show() ##连接设置 self.sld.valueChanged[int].connect(self.sld\u changeValue) self.vp.finished.connect(self.onReachingFinish) self.btn\u play.clicked.connect(self.onClicked\u play) self.btn\u go\u next.clicked.connect(self.onClicked\u nextClip) self.btn\u go\u prev.clicked.connect(self.onClicked\u prevClip) ######################可调用函数################## def sld_更改值(自身,值): totalT=self.vp.totalTime() 打印总数 牛顿=总T*值/1000 seek副总裁(纽特) def onClicked_播放(自): #边界有问题吗 如果self.vp.isPaused(): self.vp.play() 打印(“继续播放”) elif self.vp.isPlaying(): self.vp.pause() 打印(“暂停”,self.sld.value())
elif self.sld.value()声子中有一个专门的类:
Phonon.SeekSlider

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        # creating player resource
        self.player = Player()
        # adding controls
        self.sliders = Sliders(self.player)

class Sliders(QtGui.QWidget):
    def __init__(self, player):
        QtGui.QWidget.__init__(self)
        self.seek_slider = Phonon.SeekSlider(player , self)

class Player(Phonon.MediaObject):
    def __init__(self):
        Phonon.MediaObject.__init__(self)
        self.audioOutput = Phonon.AudioOutput(Phonon.MusicCategory, self)
        self.path = Phonon.createPath(self, self.audioOutput)
此滑块将直接引导播放,其位置将在媒体播放期间更新。但是,由于这是一个缺点,我正在寻找解决方法,因此没有
valueChanged
信号:-/