在QWebEngineView中显示(youtube)视频

时间:2019-06-24 13:09:54

标签: qt youtube qwebengineview video-codecs

我有一个使用QWebEngineView (Qt 5.9)的WebBrowser应用程序。我要加载一个页面,其中嵌入了YouTube视频。页面加载完美,但是视频无法正常工作。 我尝试启动时收到的消息是:
Requests to the server have been blocked by an extension

我试图激活插件并设置功能许可,但没有任何区别。

m_webView->settings()->setAttribute(QWebEngineSettings::PluginsEnabled, true);

m_webView->page()->setFeaturePermission(QUrl("https://www.youtube.com/watch?v=rNSnfXl1ZjU"),
                                    QWebEnginePage::MediaAudioVideoCapture,
                                    QWebEnginePage::PermissionGrantedByUser);

我是Qt的新手。我需要启用视频编解码器吗? 预先非常感谢您,希望您能帮助我。

1 个答案:

答案 0 :(得分:0)

以下小型应用程序可以根据需要运行。如果我在小型应用程序中取消注释设置部分,则会锁定YouTube视频的播放。

我建议您手动手动激活所有设置,以找出阻止视频在您的环境中运行的原因。

控制台输出也可能有助于查找问题原因。

#include <QWebEngineView>
#include <QWebEngineSettings>
#include <QApplication>

int main(int argc, char **args)
{
    QApplication app(argc, args);
    auto view = new QWebEngineView; 
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::AllowGeolocationOnInsecureOrigins, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::Accelerated2dCanvasEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::AllowRunningInsecureContent, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::AllowWindowActivationFromJavaScript, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::JavascriptCanAccessClipboard, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::FullScreenSupportEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::JavascriptCanOpenWindows, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::JavascriptEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::ScreenCaptureEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::PluginsEnabled, false);
    //view->settings()->setAttribute(QWebEngineSettings::WebAttribute::LocalStorageEnabled, false);

    view->setUrl(QUrl("https://www.youtube.com/watch?v=rNSnfXl1ZjU"));
    view->show();
    app.exec();
}

停用所有设置后,我将获得以下控制台输出:

js: Refused to display 'https://accounts.google.com/ServiceLogin?continue=https%3A%2F%2Fwww.youtube.com%2Fsignin%3Fnext%3D%252Fsignin_passive%26hl%3Dde%26feature%3Dpassive%26app%3Ddesktop%26action_handle_signin%3Dtrue&hl=de&passive=true&service=youtube&uilel=3' in a frame because it set 'X-Frame-Options' to 'deny'.