Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to play youtube video on the ui
Forum Updated to NodeBB v4.3 + New Features

How to play youtube video on the ui

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 3.3k Views 1 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.
  • G Offline
    G Offline
    greencow
    wrote on last edited by
    #1

    I would like to play the video from youtube but I couldn't make it. Can anyone please help !
    Here are my code:

    QT       += core gui multimedia multimediawidgets // this is added in the .pro
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    #include <QMediaPlayer>
    #include <QVideoWidget>
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QMediaPlayer *player = new QMediaPlayer;
            
        QMediaContent *mc=new QMediaContent(QUrl("https://www.youtube.com/watch?v=ksBjyegtBKE"));
        
        player->setMedia(*mc);
        
        
        player->setVolume(50);
        
        QVideoWidget *videoWidget = new QVideoWidget;
        
        videoWidget->resize(700,700);
        
        videoWidget->show();
        
        player->setVideoOutput(videoWidget);
        
        player->play();
    
        
        
        qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();
        
        qDebug()<<player->errorString();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    These are the code in mainwindow.cpp

    and I got an error

    () QUrl("https://www.youtube.com/watch?v=ksBjyegtBKE")
    ""
    DirectShowPlayerService::doRender: Unresolved error code 0x80040218 ()

    How can I fix the problem or any other way to play the video ?

    Thank you for helping !

    raven-worxR 1 Reply Last reply
    0
    • G greencow

      I would like to play the video from youtube but I couldn't make it. Can anyone please help !
      Here are my code:

      QT       += core gui multimedia multimediawidgets // this is added in the .pro
      
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      #include <QMediaPlayer>
      #include <QVideoWidget>
      #include <QDebug>
      
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          QMediaPlayer *player = new QMediaPlayer;
              
          QMediaContent *mc=new QMediaContent(QUrl("https://www.youtube.com/watch?v=ksBjyegtBKE"));
          
          player->setMedia(*mc);
          
          
          player->setVolume(50);
          
          QVideoWidget *videoWidget = new QVideoWidget;
          
          videoWidget->resize(700,700);
          
          videoWidget->show();
          
          player->setVideoOutput(videoWidget);
          
          player->play();
      
          
          
          qDebug()<<player->availableMetaData()<<player->currentMedia().canonicalUrl();
          
          qDebug()<<player->errorString();
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      

      These are the code in mainwindow.cpp

      and I got an error

      () QUrl("https://www.youtube.com/watch?v=ksBjyegtBKE")
      ""
      DirectShowPlayerService::doRender: Unresolved error code 0x80040218 ()

      How can I fix the problem or any other way to play the video ?

      Thank you for helping !

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @greencow said in How to play youtube video on the ui:

      new QMediaContent(QUrl("https://www.youtube.com/watch?v=ksBjyegtBKE"));

      the url doesn't provide a video stream, but the youtube HTML page of the video.

      Take a look at this.
      Youtube videos use RMTP streaming protocol.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      G 1 Reply Last reply
      3
      • raven-worxR raven-worx

        @greencow said in How to play youtube video on the ui:

        new QMediaContent(QUrl("https://www.youtube.com/watch?v=ksBjyegtBKE"));

        the url doesn't provide a video stream, but the youtube HTML page of the video.

        Take a look at this.
        Youtube videos use RMTP streaming protocol.

        G Offline
        G Offline
        greencow
        wrote on last edited by
        #3

        @raven-worx Thank you for helping !!!!

        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