开发者

python-mplayer closes immediately

开发者 https://www.devze.com 2023-03-16 09:09 出处:网络
Consider the following example: import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from mplayer import *

Consider the following example:

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


class mplayerStarter(QMainWindow):
    def __init__(self, parent=N开发者_C百科one):
        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_()

If I invoke the program and press the button, the video appears but vanishes immediatly. Any idea how to fix this?


I think it might be being garbage collected. Try this:

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消