Qt 5.3.2 QtQuick QML application does not play YouTube videos
I have a basic WebView control and a Qt SDK 5.3.2. I tried to watch some YouTube videos. In fact, the sound is only reproduced. But don't do the video.
Only black screen is displayed:
import QtQuick 2.3
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
import QtWebKit 3.0
import QtWebKit.experimental 1.0
ScrollView {
anchors.fill: parent
WebView {
id: webview
anchors.fill: parent
url: "https://www.youtube.com/"
experimental.preferences.pluginsEnabled: true
onNavigationRequested: {
request.action = WebView.AcceptRequest;
}
}
}
After finding some clues, I found out a way to test the loaded page:
url: "http://www.youtube.com/html5"
This url shows me the following result:
What can I do to make the following functions available in my application:
- Media Source MSE Extension
- MSE and H.264
- MSE and Web VP9
source to share
It might be a Qtwebkit issue, now QT does not support Qtwebkit, so I think it is better to switch to QTwebengine, here is the webengine code example. The web engine initialization part looks like this
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QtWebEngine::initialize();
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
Qml part for loading a webpage
import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.0
Window {
width: 1024
height: 750
visible: true
WebEngineView {
anchors.fill: parent
url: "http://www.qt.io"
}
}
See this link for details. http://doc.qt.io/qt-5/qtwebengine-webengine-minimal-example.html
MSE will support QT 5.5, proprietary codecs can be enabled by passing the following qmake parameter when creating a Qt WebEngine:
qmake WEBENGINE_CONFIG+=use_proprietary_codecs
source to share
I tried the same in Qt 5.4.0 and for me it won't play YouTube videos at all (just displays an error and prompts to reload the page).
The problem seems to lie with the element WebView
(WebKit).
What I've done:
- installed Qt 5.4.0 MSVC version
- imported QtWebEngine
- used element
WebEngineView
And it worked.
Please be aware that WebKit will be deprecated in the next version of Qt and you will need to switch to Chromium (QtWebEngine).
Literature:
https://www.qtdeveloperdays.com/2013/sites/default/files/presentation_pdf/Webkit.pdf
http://www.qt.io/qt5-4/?utm_source=qtproject&utm_medium=banner&utm_campaign=qt54release#section-3
source to share