Question

I would like to place a phonon videowidget onto a qgraphicsscene so I can overlay graphics etc. When I run the following I get the sound, but no video playing on the qgraphicsview. Help would be appreciated as I thought I was doing as the examples show. However, I suspect its something in how I have understood videoplayer and videowidget.

For testing I am just playing a video straight from a file.

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()
Was it helpful?

Solution

Ok - think I've sorted it (to an extent). Simple case of:

self.videoWidget.setMinimumSize(640,480)

The video doesn't really run very well - breaks up a lot but at least I can draw on it :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top