1

我想在 qgraphicsscene 上放置一个声子视频小部件,以便我可以覆盖图形等。当我运行以下命令时,我得到了声音,但 qgraphicsview 上没有视频播放。帮助将不胜感激,因为我认为我正在做的例子显示。但是,我怀疑这与我对 videoplayer 和 videowidget 的理解有关。

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

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()
4

1 回答 1

2

好的 - 认为我已经对它进行了排序(在一定程度上)。简单案例:

self.videoWidget.setMinimumSize(640,480)

视频运行得不太好——经常中断,但至少我可以借鉴它:)

于 2012-08-26T17:02:53.590 回答