关于qgraphicsview的Phonon视频单元

时间:2012-08-25 18:02:44

标签: python qt pyside phonon qgraphicsscene

我想在qgraphicsscene上放置一个声子视频,这样我就可以覆盖图形等。当我运行以下内容时,我得到了声音,但没有在qgraphicsview上播放视频。帮助将被欣赏,因为我认为我正在做的例子显示。但是,我怀疑它是如何理解视频播放器和视频播放器的。

为了测试,我只是直接从文件中播放视频。

from PySide import QtGui, QtCore
from PySide.phonon import Phonon
from window import Ui_MainWindow # main GUI window
import os, sys

class DiagramScene(QtGui.QGraphicsScene):
    InsertItem, InsertLine, InsertText, MoveItem  = range(4)

    def __init__(self):
        super(DiagramScene, self).__init__()
        self.myLineColor = QtCore.Qt.black
        self.myMode = "Start"
        self.line = None

    def mousePressEvent(self, mouseEvent):
        if (mouseEvent.button() == QtCore.Qt.LeftButton):
            if self.myMode == "Start":
                self.line = QtGui.QGraphicsLineItem(QtCore.QLineF(mouseEvent.scenePos(), mouseEvent.scenePos()))
                self.addItem(self.line)
        elif (mouseEvent.button() == QtCore.Qt.RightButton):
            self.addText("Hello")
        super(DiagramScene, self).mousePressEvent(mouseEvent)

    def mouseMoveEvent(self, mouseEvent):
        if self.line:
            newLine = QtCore.QLineF(self.line.line().p1(), mouseEvent.scenePos())
            self.line.setLine(newLine)

    def mouseReleaseEvent(self, mouseEvent):
        self.line = None
        super(DiagramScene, self).mouseReleaseEvent(mouseEvent)

class QPlayer(QtGui.QWidget):

    def __init__(self):
        super(QPlayer, self).__init__()
        media_src = Phonon.MediaSource("C:\Users\Public\Videos\Sample Videos\Wildlife.wmv")
        self.audioOuptut=Phonon.AudioOutput(Phonon.MusicCategory, self)
        self.player=Phonon.MediaObject(self)
        self.player.setCurrentSource(media_src)
        Phonon.createPath(self.player, self.audioOuptut)
        self.videoWidget=Phonon.VideoWidget(self)
        self.videoWidget.FitInView
        Phonon.createPath(self.player, self.videoWidget)
        self.player.play()

class Main(QtGui.QMainWindow):
    def __init__(self):
        super(Main, self).__init__()
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)
        self.scene = DiagramScene()
        self.scene.addWidget(QPlayer())
        self.gview = self.ui.gView
        self.gview.setScene(self.scene)

def main():
    app = QtGui.QApplication(sys.argv)
    window=Main()
    window.show()
    sys.exit(app.exec_())

if __name__ == "__main__":
    main()

1 个答案:

答案 0 :(得分:2)

好的 - 我想我已经对它进行了排序(在某种程度上)。简单的例子:

self.videoWidget.setMinimumSize(640,480)

该视频并没有真正运行良好 - 分手很多但至少我可以借鉴它:)