I embed youtube within QML WebEngineView. Everything is working fine but only the autoplay is not working. I try to add ( ?autoplay=1 ) after URL as this answer How can I autoplay a video using the new embed code style for Youtube? but It still not working.
Here is my QML code.
ApplicationWindow {
id: root
visible: true
width: 576; height: 400
title: "Test"
x: 0;y: 0;
WebEngineView {
id: webViewID
anchors.fill: parent
backgroundColor: "black"
}
Component.onCompleted: {
webViewID.loadHtml('<iframe id="ms-youtube" width="100%" height="100%" src="https: //www.youtube.com/embed/-mN3VyJuCjM?autoplay=1 " title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
}
}
pyqt5 qwebenginview doesn't autoplay youtube videos
You need to add settings.playbackRequiresUserGesture: false
to your WebEngineView
instance. Check Qts documentation for more information about why https://doc.qt.io/qt-6/qml-qtwebengine-webenginesettings.html#playbackRequiresUserGesture-prop
ApplicationWindow {
id: root
visible: true
width: 576
height: 400
title: "Test"
WebEngineView {
id: webViewID
anchors.fill: parent
backgroundColor: "black"
settings.playbackRequiresUserGesture: false
}
Component.onCompleted: {
webViewID.url = "https://www.youtube.com/embed/-mN3VyJuCjM?autoplay=1"
}
}