youtube视频嵌入pyqt

时间:2018-01-04 21:15:59

标签: python qt pyqt pyqt5

如何使用PyQt5嵌入YouTube视频?我尝试了以下操作,但它给了我一个未解决的错误:

  

DirectShowService:doRender未解决的错误代码

MainComponent::MainComponent (Audio& audio_) : audio (audio_)
{


setSize (500, 400);
addAndMakeVisible(filePlayerGui[0]);
addAndMakeVisible(filePlayerGui[1]);
}

MainComponent::~MainComponent()
{

}

 void MainComponent::resized()
 {
filePlayerGui[0].setBounds (0, 0, getWidth(), 40);
 }

   //MenuBarCallbacks==============================================================
 StringArray MainComponent::getMenuBarNames()
{
const char* const names[] = { "File", 0 };
return StringArray (names);
}

PopupMenu MainComponent::getMenuForIndex (int topLevelMenuIndex, const String& menuName)
{
PopupMenu menu;
if (topLevelMenuIndex == 0)
    menu.addItem(AudioPrefs, "Audio Prefrences", true, false);
return menu;
}

void MainComponent::menuItemSelected (int menuItemID, int topLevelMenuIndex)
{
if (topLevelMenuIndex == FileMenu)
{
    if (menuItemID == AudioPrefs)
    {
        AudioDeviceSelectorComponent audioSettingsComp (audio.getAudioDeviceManager(),
                                                        0, 2, 2, 2, true, true, true, false);
        audioSettingsComp.setSize (450, 350);
        DialogWindow::showModalDialog ("Audio Settings",
                                       &audioSettingsComp, this, Colours::lightgrey, true);
    }
}
}

1 个答案:

答案 0 :(得分:2)

您正在从PyQt5(QtWebKitQtWebKitWidgets)导入一些已弃用的模块。您似乎在导入的底部注释了正确的路径。

如果您解决了这些问题并使用了正确的模块(QtWebEngineCoreQtWebEngineWidgets),则它可以在我的系统上运行。

from PyQt5 import QtWidgets,QtCore,QtGui
import sys, time
from PyQt5.QtCore import Qt,QUrl
from PyQt5 import QtWebEngineWidgets
from PyQt5 import QtWebEngineCore
from PyQt5.QtWebEngineWidgets import QWebEngineSettings

class window(QtWidgets.QMainWindow):
    def __init__(self):
        QWebEngineSettings.globalSettings().setAttribute(QWebEngineSettings.PluginsEnabled,True)
        super(window,self).__init__()
        self.centralwid=QtWidgets.QWidget(self)
        self.vlayout=QtWidgets.QVBoxLayout()
        self.webview=QtWebEngineWidgets.QWebEngineView()
        self.webview.setUrl(QUrl("https://www.youtube.com/watch?v=Mq4AbdNsFVw"))
        self.vlayout.addWidget(self.webview)
        self.centralwid.setLayout(self.vlayout)
        self.setCentralWidget(self.centralwid)
        self.show()

app=QtWidgets.QApplication([])
ex=window()
sys.exit(app.exec_())

我得到的输出如下(看起来是正确的):

enter image description here