Pyside声子显示空的正方形

时间:2019-01-25 11:45:11

标签: python pyside phonon

我试图将Phonon Video Playback添加到我的pyside应用程序中,以显示列出的视频的预览。但是我的代码返回的是空的(白色),没有任何视频。

我正在尝试使用here中的示例脚本,它可以完美地工作(在同一文件上)。因此声子似乎可以正常工作。

这是我的示例代码:

from lib.qt_main import Ui_qt_main as QtMainWindow
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.phonon import Phonon

class QtMain(QWidget, QtMainWindow):
    def __init__(self):
        super(QtMain, self).__init__()
        self.setupUi(self)

        self.imp_adv.clicked.connect(self.play)

    def play(self):
        src = r"C:\Users\jpetruk\Desktop\New folder\tego_link_2.mp4"
        media_src = Phonon.MediaSource(src)

        media_obj = Phonon.MediaObject()
        media_obj.setCurrentSource(media_src)

        Phonon.createPath(media_obj, self.lib_prv)

        media_obj.play()

self.lib_prv是我的Phonon.VideoWidget()

from PySide import QtCore, QtGui
from PySide.phonon import Phonon

class Ui_qt_main(object):
    def setupUi(self, qt_main):
        qt_main.setObjectName("qt_main")
        qt_main.setWindowModality(QtCore.Qt.WindowModal)
        qt_main.setEnabled(True)
        qt_main.resize(968, 656)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(qt_main.sizePolicy().hasHeightForWidth())
        qt_main.setSizePolicy(sizePolicy)
        self.gridLayout = QtGui.QGridLayout(qt_main)
        self.gridLayout.setObjectName("gridLayout")
        self.main = QtGui.QVBoxLayout()
        self.main.setContentsMargins(6, 6, 6, 6)
        self.main.setObjectName("main")
        self.cat = QtGui.QHBoxLayout()
        self.cat.setObjectName("cat")
        self.cat_typ = QtGui.QComboBox(qt_main)
        self.cat_typ.setMinimumSize(QtCore.QSize(150, 0))
        self.cat_typ.setEditable(False)
        self.cat_typ.setObjectName("cat_typ")
        self.cat.addWidget(self.cat_typ)
        self.cat_cat = QtGui.QComboBox(qt_main)
        self.cat_cat.setMinimumSize(QtCore.QSize(150, 0))
        self.cat_cat.setObjectName("cat_cat")
        self.cat.addWidget(self.cat_cat)
        self.cat_sub = QtGui.QComboBox(qt_main)
        self.cat_sub.setMinimumSize(QtCore.QSize(150, 0))
        self.cat_sub.setObjectName("cat_sub")
        self.cat.addWidget(self.cat_sub)
        self.cat_btn = QtGui.QPushButton(qt_main)
        self.cat_btn.setMinimumSize(QtCore.QSize(75, 0))
        self.cat_btn.setObjectName("cat_btn")
        self.cat.addWidget(self.cat_btn)
        spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
        self.cat.addItem(spacerItem)
        self.car_srch = QtGui.QLineEdit(qt_main)
        self.car_srch.setMinimumSize(QtCore.QSize(150, 0))
        self.car_srch.setObjectName("car_srch")
        self.cat.addWidget(self.car_srch)
        self.cat_srch_btn = QtGui.QPushButton(qt_main)
        self.cat_srch_btn.setMinimumSize(QtCore.QSize(75, 0))
        self.cat_srch_btn.setObjectName("cat_srch_btn")
        self.cat.addWidget(self.cat_srch_btn)
        self.main.addLayout(self.cat)
        self.frame = QtGui.QFrame(qt_main)
        self.frame.setObjectName("frame")
        self.lib = QtGui.QHBoxLayout(self.frame)
        self.lib.setObjectName("lib")
        self.lib_tab = QtGui.QTableWidget(self.frame)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.lib_tab.sizePolicy().hasHeightForWidth())
        self.lib_tab.setSizePolicy(sizePolicy)
        self.lib_tab.setStyleSheet("")
        self.lib_tab.setFrameShape(QtGui.QFrame.NoFrame)
        self.lib_tab.setFrameShadow(QtGui.QFrame.Plain)
        self.lib_tab.setLineWidth(0)
        self.lib_tab.setMidLineWidth(0)
        self.lib_tab.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.lib_tab.setAutoScroll(True)
        self.lib_tab.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers)
        self.lib_tab.setDragDropOverwriteMode(False)
        self.lib_tab.setAlternatingRowColors(True)
        self.lib_tab.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
        self.lib_tab.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
        self.lib_tab.setIconSize(QtCore.QSize(128, 128))
        self.lib_tab.setTextElideMode(QtCore.Qt.ElideMiddle)
        self.lib_tab.setShowGrid(False)
        self.lib_tab.setColumnCount(11)
        self.lib_tab.setObjectName("lib_tab")
        self.lib_tab.setColumnCount(11)
        self.lib_tab.setRowCount(0)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(0, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(1, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(2, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(3, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(4, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(5, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(6, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(7, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(8, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(9, item)
        item = QtGui.QTableWidgetItem()
        self.lib_tab.setHorizontalHeaderItem(10, item)
        self.lib_tab.horizontalHeader().setVisible(True)
        self.lib_tab.horizontalHeader().setDefaultSectionSize(128)
        self.lib_tab.horizontalHeader().setMinimumSectionSize(128)
        self.lib_tab.horizontalHeader().setStretchLastSection(True)
        self.lib_tab.verticalHeader().setVisible(False)
        self.lib_tab.verticalHeader().setCascadingSectionResizes(True)
        self.lib_tab.verticalHeader().setDefaultSectionSize(128)
        self.lib_tab.verticalHeader().setMinimumSectionSize(64)
        self.lib_tab.verticalHeader().setStretchLastSection(False)
        self.lib.addWidget(self.lib_tab)
        self.frame1 = QtGui.QFrame(self.frame)
        self.frame1.setObjectName("frame1")
        self.lib_rig = QtGui.QVBoxLayout(self.frame1)
        self.lib_rig.setObjectName("lib_rig")
        self.lib_prv = Phonon.VideoWidget()
        # sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Expanding)
        # sizePolicy.setHorizontalStretch(0)
        # sizePolicy.setVerticalStretch(0)
        # sizePolicy.setHeightForWidth(self.lib_prv.sizePolicy().hasHeightForWidth())
        # self.lib_prv.setSizePolicy(sizePolicy)
        # self.lib_prv.setMinimumSize(QtCore.QSize(256, 0))
        # self.lib_prv.setLayoutDirection(QtCore.Qt.LeftToRight)
        # self.lib_prv.setObjectName("lib_prv")
        self.lib_rig.addWidget(self.lib_prv)
        self.lib.addWidget(self.frame1)
        self.main.addWidget(self.frame)
        self.imp = QtGui.QHBoxLayout()
        self.imp.setObjectName("imp")
        self.imp_btn = QtGui.QPushButton(qt_main)
        self.imp_btn.setCheckable(False)
        self.imp_btn.setObjectName("imp_btn")
        self.imp.addWidget(self.imp_btn)
        spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Minimum)
        self.imp.addItem(spacerItem1)
        self.imp_fld = QtGui.QPushButton(qt_main)
        self.imp_fld.setObjectName("imp_fld")
        self.imp.addWidget(self.imp_fld)
        self.imp_prv = QtGui.QPushButton(qt_main)
        self.imp_prv.setObjectName("imp_prv")
        self.imp.addWidget(self.imp_prv)
        spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Minimum)
        self.imp.addItem(spacerItem2)
        self.imp_add = QtGui.QPushButton(qt_main)
        self.imp_add.setMaximumSize(QtCore.QSize(75, 16777215))
        self.imp_add.setObjectName("imp_add")
        self.imp.addWidget(self.imp_add)
        self.imp_com = QtGui.QPushButton(qt_main)
        self.imp_com.setObjectName("imp_com")
        self.imp.addWidget(self.imp_com)
        self.imp_adv = QtGui.QPushButton(qt_main)
        self.imp_adv.setObjectName("imp_adv")
        self.imp.addWidget(self.imp_adv)
        spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Minimum)
        self.imp.addItem(spacerItem3)
        self.imp_can = QtGui.QPushButton(qt_main)
        self.imp_can.setObjectName("imp_can")
        self.imp.addWidget(self.imp_can)
        self.main.addLayout(self.imp)
        self.gridLayout.addLayout(self.main, 0, 0, 1, 1)

        self.retranslateUi(qt_main)
        QtCore.QMetaObject.connectSlotsByName(qt_main)

    def retranslateUi(self, qt_main):
        qt_main.setWindowTitle(QtGui.QApplication.translate("qt_main", "Form", None, QtGui.QApplication.UnicodeUTF8))
        self.cat_btn.setText(QtGui.QApplication.translate("qt_main", "Select", None, QtGui.QApplication.UnicodeUTF8))
        self.cat_srch_btn.setText(QtGui.QApplication.translate("qt_main", "Search", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.setSortingEnabled(False)
        self.lib_tab.horizontalHeaderItem(0).setText(QtGui.QApplication.translate("qt_main", "Miniature", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(1).setText(QtGui.QApplication.translate("qt_main", "Name", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(2).setText(QtGui.QApplication.translate("qt_main", "Stats", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(3).setText(QtGui.QApplication.translate("qt_main", "Comment", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(4).setText(QtGui.QApplication.translate("qt_main", "Frame_in", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(5).setText(QtGui.QApplication.translate("qt_main", "Frame_out", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(6).setText(QtGui.QApplication.translate("qt_main", "Path", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(7).setText(QtGui.QApplication.translate("qt_main", "Type", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(8).setText(QtGui.QApplication.translate("qt_main", "Id", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(9).setText(QtGui.QApplication.translate("qt_main", "Prev", None, QtGui.QApplication.UnicodeUTF8))
        self.lib_tab.horizontalHeaderItem(10).setText(QtGui.QApplication.translate("qt_main", "Link", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_btn.setText(QtGui.QApplication.translate("qt_main", "Import", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_fld.setText(QtGui.QApplication.translate("qt_main", "Folder", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_prv.setText(QtGui.QApplication.translate("qt_main", "Preview", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_add.setText(QtGui.QApplication.translate("qt_main", "Add", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_com.setText(QtGui.QApplication.translate("qt_main", "Comment", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_adv.setText(QtGui.QApplication.translate("qt_main", "Advance", None, QtGui.QApplication.UnicodeUTF8))
        self.imp_can.setText(QtGui.QApplication.translate("qt_main", "Cancel", None, QtGui.QApplication.UnicodeUTF8))

我在做什么错了,我该如何纠正?

0 个答案:

没有答案