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:

Qt Code:
  1. cmake_minimum_required(VERSION 3.16)
  2.  
  3. project(youtube_video VERSION 0.1 LANGUAGES CXX)
  4.  
  5. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  6.  
  7. find_package(Qt6 6.4 REQUIRED COMPONENTS Quick WebEngineQuick)
  8.  
  9. qt_standard_project_setup()
  10.  
  11. qt_add_executable(appyoutube_video
  12. main.cpp
  13. )
  14.  
  15. qt_add_qml_module(appyoutube_video
  16. URI youtube_video
  17. VERSION 1.0
  18. QML_FILES Main.qml
  19. )
  20.  
  21. # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
  22. # If you are developing for iOS or macOS you should consider setting an
  23. # explicit, fixed bundle identifier manually though.
  24. set_target_properties(appyoutube_video PROPERTIES
  25. # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appyoutube_video
  26. MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
  27. MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
  28. MACOSX_BUNDLE TRUE
  29. WIN32_EXECUTABLE TRUE
  30. )
  31.  
  32. target_link_libraries(appyoutube_video
  33. PRIVATE Qt6::Quick Qt6::WebEngineQuick
  34. )
  35.  
  36. include(GNUInstallDirs)
  37. install(TARGETS appyoutube_video
  38. BUNDLE DESTINATION .
  39. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  40. RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
  41. )
To copy to clipboard, switch view to plain text mode 

main.cpp file:

Qt Code:
  1. #include <QGuiApplication>
  2. #include <QQmlApplicationEngine>
  3. #include <QtWebEngineQuick/qtwebenginequickglobal.h>
  4.  
  5. int main(int argc, char *argv[]) {
  6. QtWebEngineQuick::initialize();
  7. QGuiApplication app(argc, argv);
  8.  
  9. QQmlApplicationEngine engine;
  10. const QUrl url(u"qrc:/youtube_video/Main.qml"_qs);
  11. QObject::connect(
  12. &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
  13. engine.load(url);
  14.  
  15. return app.exec();
  16. }
To copy to clipboard, switch view to plain text mode 

Main.qml file:

Qt Code:
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Window
  4. import QtWebEngine
  5.  
  6. Window {
  7. width: 640
  8. height: 480
  9. visible: true
  10. title: qsTr("Hello World")
  11.  
  12. WebEngineView {
  13. anchors.fill: parent
  14. url: "https://www.youtube.com/embed/cabBXCq7_P8"
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

Shows a preview after launch:

01.jpg

But trying to play the video results in an error:

02.jpg

If change url to: "https://www.youtube.com/watch?v=cabBXCq7_P8"

Qt Code:
  1. import QtQuick
  2. import QtQuick.Controls
  3. import QtQuick.Window
  4. import QtWebEngine
  5.  
  6. Window {
  7. width: 640
  8. height: 480
  9. visible: true
  10. title: qsTr("Hello World")
  11.  
  12. WebEngineView {
  13. id: webView
  14. anchors.fill: parent
  15. url: "https://www.youtube.com/watch?v=cabBXCq7_P8" //"https://www.youtube.com/embed/cabBXCq7_P8"
  16. }
  17. }
To copy to clipboard, switch view to plain text mode 

We will receive a message: You browser can't play this video

03.png

Can anyone help me what the error is and how to fix it?
As a result, the video is expected to play