Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

qml - Why qt webengine can't play youtube live video streams

I was creating a simple webbrowser using webengine. I went to youtube and tried to play a live stream but failed. Same thing happens with every video which requires HTML5 video support in browsers. I didn't saw any recent problems which are identical to this. Qt says that webengine has HTML5 support from they released Qt5. Some old answers to same questions suggest them to compile qtwebengine your own. I tried several attempts and failed(may be my computer can't do the job). Some other say to enable proprietary plugins from the code. But in my case it too didn't work.

Running the code also logs an error WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.

So this is my simple qml code.

import QtQuick 2.12
import QtQuick.Window 2.12
import QtWebEngine 1.0

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")
    WebEngineView{
        anchors.fill:parent
        url:"https://www.youtube.com/watch?v=iL53Y28Rp84"
    }
}

Qt version: 5.15.1(GNU Public License )

Installed using qt online installer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your problem is likely that - as the error in the console said - you haven't initialized the web engine. In your main(), you must call QtWebEngine::initialize() before you do any rendering. So your main function should look like this:

#include <QtWebEngine>

int main(int argc, char* argv[]) 
{
    QGuiApplication a(argc, argv);
    QtWebEngine::initialize();
    (...)
}

As per the Qt documentation, the initialize() function makes sure that the OpenGL context can be shared between the GUI and the renderer process. Link to the Qt documentation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...