gpt4 book ai didi

python - qgraphicsview 上的声子视频小部件

转载 作者:行者123 更新时间:2023-12-01 05:56:49 26 4
gpt4 key购买 nike

我想将声子视频小部件放置到 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()

最佳答案

好的 - 我想我已经对它进行了排序(在一定程度上)。简单情况:

self.videoWidget.setMinimumSize(640,480)

该视频运行得不太好 - 断断续续,但至少我可以在上面画画:)

关于python - qgraphicsview 上的声子视频小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12124382/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com