QML WebEngineView doesn't play YouTube video if the video hasn't 480p quality
Unsolved
QtWebEngine
-
QML WebEngineView doesn't play YouTube video if the video hasn't 480p quality
The program was written using version Qt 6.4.3
CMakeLists.txt file:cmake_minimum_required(VERSION 3.16) project(youtube_video VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.4 REQUIRED COMPONENTS Quick WebEngineQuick) qt_standard_project_setup() qt_add_executable(appyoutube_video main.cpp ) qt_add_qml_module(appyoutube_video URI youtube_video VERSION 1.0 QML_FILES Main.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. set_target_properties(appyoutube_video PROPERTIES # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appyoutube_video MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(appyoutube_video PRIVATE Qt6::Quick Qt6::WebEngineQuick ) include(GNUInstallDirs) install(TARGETS appyoutube_video BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )
main.cpp file:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QtWebEngineQuick/qtwebenginequickglobal.h> int main(int argc, char *argv[]) { QtWebEngineQuick::initialize(); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(u"qrc:/youtube_video/Main.qml"_qs); QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
Main.qml file:
import QtQuick import QtQuick.Controls import QtQuick.Window import QtWebEngine Window { width: 640 height: 480 visible: true title: qsTr("Hello World") WebEngineView { anchors.fill: parent url: "https://www.youtube.com/embed/cabBXCq7_P8" } }
Shows a preview after launch:
But trying to play the video results in an error:
If change url to: "https://www.youtube.com/watch?v=cabBXCq7_P8"import QtQuick import QtQuick.Controls import QtQuick.Window import QtWebEngine Window { width: 640 height: 480 visible: true title: qsTr("Hello World") WebEngineView { id: webView anchors.fill: parent url: "https://www.youtube.com/watch?v=cabBXCq7_P8" //"https://www.youtube.com/embed/cabBXCq7_P8" } }
We will receive a message: You browser can't play this video
Can anyone help me what the error is and how to fix it?
As a result, the video is expected to play -
Do you have a solution for that problem? I need.