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. Qt does not play video
Qt 6.11 is out! See what's new in the release blog

Qt does not play video

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 890 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by Mikeeeeee
    #1

    Hi!
    Qt does not play video.
    How to play video?
    This myCode.

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QtMultimedia/QMediaPlayer>
    #include <QtMultimedia/QMediaPlaylist>
    #include <QtMultimediaWidgets/QVideoWidget>
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        QMediaPlayer *player = new QMediaPlayer;
    
        QMediaPlaylist *playlist = new QMediaPlaylist(player);
        playlist->addMedia(QUrl("C:/Users/New Owner/Downloads/example.mp4"));
        playlist->addMedia(QUrl("C:/Users/Public/Videos/Sample Videos/Живая природа.wmv"));
    
        QVideoWidget *videoWidget = new QVideoWidget(this);
        videoWidget->setSizeIncrement(600,600);
        player->setVideoOutput(videoWidget);
    
        videoWidget->show();
        playlist->setCurrentIndex(0);
        player->play();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

    This too not works

        QMediaPlayer* player = new QMediaPlayer(this);
    
        QGraphicsVideoItem *item = new QGraphicsVideoItem;
        player->setVideoOutput(item);
        QGraphicsView * graphicsView = new QGraphicsView(this);
        graphicsView->scene()->addItem(item);
        graphicsView->show();
    
        player->setMedia(QUrl("C:/Users/Public/Videos/Sample Videos/Живая природа.wmv"));
        player->play();
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Try with QUrl::fromLocalFile.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        its too not works

            QMediaPlayer *player = new QMediaPlayer;
        
            QMediaPlaylist *playlist = new QMediaPlaylist(player);
            playlist->addMedia(QUrl::fromLocalFile("C:/Users/New Owner/Downloads/example.mp4"));
            playlist->addMedia(QUrl::fromLocalFile("C:/Users/New Owner/Downloads/example.wmv"));
        
            QVideoWidget *videoWidget = new QVideoWidget(this);
            videoWidget->setSizeIncrement(600,600);
            player->setVideoOutput(videoWidget);
        
            videoWidget->show();
            playlist->setCurrentIndex(1);
            player->play();
        

        but this works

        #include <QApplication>
        #include <QMainWindow>
        #include <QVideoWidget>
        #include <QMediaPlayer>
        #include <QMediaPlaylist>
         
        int main(int argc, char * argv[])
        {
            QApplication testApp(argc, argv);
            QMainWindow w;
         
            QVideoWidget videoWidget(&w);
            w.setCentralWidget(&videoWidget);
         
            QMediaPlayer *player = new QMediaPlayer(&w);
         
            player->setMedia( QUrl::fromLocalFile("E:\\big_buck_bunny.mp4") );
            player->setVideoOutput(&videoWidget);
         
            w.show();
         
            player->play();
         
            return testApp.exec();
        }
        
        

        How do I move this solution to a class method?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Mikeeeeee
          wrote on last edited by
          #4

          Its work,but how to stretch QMediaPlayer to the whole window?

              QMediaPlayer *player = new QMediaPlayer(this);
              QVideoWidget *videoWidget = new QVideoWidget(this);
              videoWidget->setSizeIncrement(900,900);
              player->setVideoOutput(videoWidget);
          
              videoWidget->show();
              player->setMedia( QUrl::fromLocalFile("C:/Users/New Owner/Downloads/example.wmv") );
              player->play();
          
          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #5

            I create a widget in the editor, change its class to QVideoWidget and already stretch it.

            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