python-mplayer立即关闭

时间:2011-06-29 13:36:23

标签: python pyqt4 mplayer

考虑以下示例:

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from mplayer import *


class mplayerStarter(QMainWindow):
    def __init__(self, parent=None):
        super(mplayerStarter, self).__init__(parent)
        the_button = QPushButton('Start Mplayer')
        the_button.clicked.connect(self.start)
        self.setCentralWidget(the_button)

    def start(self):
        player = Player()
        player.loadfile('/tmp/video.mp4')

if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)
    form = mplayerStarter()
    form.show()
    app.exec_()

如果我调用该程序并按下按钮,视频会出现但立即消失。知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

我认为可能是垃圾收集。试试这个:

class mplayerStarter(QMainWindow):
    def __init__(self, parent=None):
        super(mplayerStarter, self).__init__(parent)
        the_button = QPushButton('Start Mplayer')
        the_button.clicked.connect(self.start)
        self.setCentralWidget(the_button)
        self.player = None

    def start(self):
        self.player = Player()
        self.player.loadfile('/tmp/video.mp4')