Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QML WebEngineView doesn't play YouTube video if the video hasn't 480p quality
Forum Updated to NodeBB v4.3 + New Features

QML WebEngineView doesn't play YouTube video if the video hasn't 480p quality

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 582 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bdfyy
    wrote on last edited by
    #1

    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:
    01.png
    But trying to play the video results in an error:
    02.png
    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
    03.png
    Can anyone help me what the error is and how to fix it?
    As a result, the video is expected to play

    1 Reply Last reply
    0
    • E Offline
      E Offline
      emircanacardev
      wrote on last edited by
      #2

      Do you have a solution for that problem? I need.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved