Skip to content Skip to sidebar Skip to footer

Youtube Video Embedding Pyqt

How Can I embed youtube video using PyQt5? I tried doing the following,but it gave me an unresolved error: DirectShowService:doRender unresolved error code from PyQt5 import QtWi

Solution 1:

You are importing some deprecated modules from PyQt5 (QtWebKit, and QtWebKitWidgets). It seems you have the right paths commented out at the bottom of your imports.

If you resolve these issues and use the proper modules (QtWebEngineCore, QtWebEngineWidgets) it works on my system.

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

classwindow(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_())

The output I get looks like the following (which seems correct):

enter image description here

Post a Comment for "Youtube Video Embedding Pyqt"