MacOSX:VLC播放器与QtWebEngine不兼容

时间:2018-08-22 07:25:38

标签: python macos pyqt libvlc qtwebengine

我有一个嵌入了VLC播放器和QtWebEngine的Python脚本,可同时播放视频和网页。

它在Windows上运行良好。当我将其移动到MacOSX上运行时,QtWebEngine页面被黑色矩形阻塞,并且VLC播放器不可见。

将VLC播放器和QtWebEngine分成单独的程序时,它们将正常工作。

这是我的脚本代码

# -*- coding: utf-8 -*-
import sys
import os
import vlc

from PySide2.QtGui import *
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtWebEngineWidgets import *

class test_widget(QWidget):

    def __init__(self, parent=None):
        super(test_widget, self).__init__(parent)
        self.__ui__()

    def __ui__(self):
        t_lay_parent = QVBoxLayout()
        t_lay_content = QHBoxLayout()
        t_lay_tool = QHBoxLayout()

        self.label_media = QLabel()
        self.webengine = QWebEngineView()
        t_lay_content.addWidget(self.label_media, 1)
        t_lay_content.addWidget(self.webengine, 1)

        self.lineedit_url = QLineEdit("http://baidu.com")
        self.button_go = QPushButton("Go")
        self.button_play = QPushButton("Play")
        t_lay_tool.addWidget(self.lineedit_url)
        t_lay_tool.addWidget(self.button_go)
        t_lay_tool.addWidget(self.button_play)

        self.button_go.clicked.connect(self.slt_go)
        self.button_play.clicked.connect(self.slt_play)

        t_lay_parent.addLayout(t_lay_content)
        t_lay_parent.addLayout(t_lay_tool)
        self.setLayout(t_lay_parent)

        self.instance = vlc.Instance("-q")
        self.m_player = self.instance.media_player_new()
        t_wid = self.label_media.winId()
        if sys.platform.startswith('linux'):  # linux
            self.m_player.set_xwindow(t_wid)
        elif sys.platform == "win32":  # windows
            self.m_player.set_hwnd(t_wid)
        elif sys.platform == "darwin":  # mac
            self.m_player.set_nsobject(t_wid)

    def slt_go(self):
        t_url = self.lineedit_url.text()
        self.webengine.setUrl(QUrl(t_url))

    def slt_play(self):
        t_media = self.instance.media_new("1.mp4")
        self.m_player.set_media(t_media)
        self.m_player.play()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    win = test_widget()
    win.show()
    sys.exit(app.exec_())

这是我的工作环境

MacOSX:10.10.5

Python:2.7.5

PyQt:5.9.0

VLC:2.2.8

0 个答案:

没有答案