为什么qt webengine不能播放youtube直播视频流 [英] Why qt webengine can't play youtube live video streams
问题描述
我正在使用 webengine 创建一个简单的网络浏览器.我去了 youtube 并尝试播放直播但失败了.每个需要在浏览器中支持 HTML5 视频的视频都会发生同样的事情.我没有看到任何与此相同的最近问题.Qt 表示 webengine 从他们发布的 Qt5 开始支持 HTML5.对相同问题的一些旧答案建议他们自己编译 qtwebengine.我尝试了几次都失败了(可能是我的电脑无法完成这项工作).其他人说从代码中启用专有插件.但就我而言,它也不起作用.
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.
运行代码也会记录一个错误 WebEngineContext used before QtWebEngine::initialize() 或 OpenGL 上下文创建失败.
Running the code also logs an error WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed.
这是我的简单 qml 代码.
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 版本:5.15.1(GNU 公共许可证)
Qt version: 5.15.1(GNU Public License )
使用 qt 在线安装程序安装.
Installed using qt online installer.
推荐答案
您收到的错误消息很简单,他们已经在另一个答案中为您提供了解决方案,而我的答案是解决根本问题.无法播放 youtube 视频,因为 Chromium(和 Qt WebEngine)不是通过启用专有编解码器编译的.解决方案是在启用该标志的情况下重新编译 Qt WebEngine.
The error message you get is trivial and they already gave you the solution in the other answer, instead my answer is to solve the underlying problem. Can't play youtube videos because chromium (and Qt WebEngine) was not compiled by enabling proprietary codecs. The solution is to recompile Qt WebEngine with that flag enabled.
从评论中可以看出OP使用的是Qt 5.15.1,所以他必须遵循以下步骤:
From the comments it can be seen that the OP is using Qt 5.15.1 so he must follow the following steps:
sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev
sudo apt-get install -y libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libxtst-dev libxss-dev libdbus-1-dev libevent-dev libfontconfig1-dev libcap-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libegl1-mesa-dev gperf bison nodejs
git clone -b 5.15.1 git://code.qt.io/qt/qtwebengine.git
cd qtwebengine
git submodule update --init
/path/of/Qt/5.15.1/gcc_64/bin/qmake . -- -webengine-proprietary-codecs
make
make install
注意:根据 /path/of/Qt/5.15.1/gcc_64/bin/qmake
注释中显示的日志,您的情况是 /mnt/volume1/main_file_folder/Home/Qt/5.15.1/gcc_64/bin/qmake
Note: According to the logs shown in the comments /path/of/Qt/5.15.1/gcc_64/bin/qmake
in your case is /mnt/volume1/main_file_folder/Home/Qt/5.15.1/gcc_64/bin/qmake
这篇关于为什么qt webengine不能播放youtube直播视频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!