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. Trying to play video with qmediaplayer and qvideowidget
Qt 6.11 is out! See what's new in the release blog

Trying to play video with qmediaplayer and qvideowidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.2k 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
    Mistrale
    wrote on last edited by
    #1

    Hi,

    Im trying to play a video with a QMediaPlayer and a QVideoWidget. I have just a MainWindow with member variables :
    QVideoWidget *_video;
    QMediaPlaplyer *_player;
    QMediaPlaylist *_playlist;

    and this in the mainwindow.cpp :

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    _player = new QMediaPlayer(this);
    _video = new QVideoWidget(this);
    _playlist = new QMediaPlaylist(this);
    
    QUrl    url = QUrl::fromLocalFile("C:\Users\*****\Downloads\Despicable Me (2010) [1080p]\test.mp4");
    _playlist->addMedia(url);
    std::cout << "C'est valide " << url.isValid() << std::endl;
    _playlist->setCurrentIndex(1);
    _player->setPlaylist(_playlist);
    _player->setVideoOutput(_video);
    _video->show();
    _player->play();
    

    // _test = new QWidget(this);
    // _test->setStyleSheet("background: blue;");
    setCentralWidget(_video);
    }

    When i try to display a simple QWidget _test with a blue background it displays it, but it doesnt work with the QVideoWidget. The url is valid and I just want to play the video.

    Does anyone have a suggestion ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Your path is wrong, either use double backslashes to escape the slash properly or do it the Qt way and use forward slashes.

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

      M 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Your path is wrong, either use double backslashes to escape the slash properly or do it the Qt way and use forward slashes.

        M Offline
        M Offline
        Mistrale
        wrote on last edited by
        #3

        @SGaist

        Indeed it works, I thought it was okey with the QUrl isValid returning true.

        Thank you !

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          A valid URL doesn't mean that it points to something valid ;)

          You're welcome !

          Since you have it working now, please mark the thread as solved using the "Topic Tool" button so other forum users may know a solution has been found :)

          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

          • Login

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