Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QMediaPlayer / QVideoWidget do not show

    General and Desktop
    4
    7
    2473
    Loading More Posts
    • 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.
    • GGAllin
      GGAllin last edited by

      Hello every one
      I have a big problem with a VideoPlayer ,
      I can hear the audio but i can't see the video.

      I'm using Qt 5.6.2 on OsX El capitan

      here's my code

      VideoPlayer::VideoPlayer(VideoMetadata* meta, QWidget* parent)
          : ContentWidget(parent)
          , metadata(meta)
          , player(new QMediaPlayer(this))
          , video(new QVideoWidget)
      {
      
          // ContentWidget is QWidget  
          QVBoxLayout* layout = new QVBoxLayout;
          layout->addWidget(video);
          setLayout(layout);
          player->setVideoOutput(video);
          player->setMedia(QUrl::fromLocalFile("/Users/me/Desktop/VIDEO_TEST/video.mp4"));
          player->stop();
      
          connect(player, &QMediaPlayer::mediaStatusChanged,
              this, &VideoPlayer::mediaStateChanged);
      
          connect(player, &QMediaPlayer::positionChanged,
              this, &VideoPlayer::positionChanged);
      }
      
      VideoPlayer::~VideoPlayer()
      {
      }
      
      
      void VideoPlayer::mediaStateChanged(QMediaPlayer::MediaStatus state)
      {
          if (state == QMediaPlayer::MediaStatus::LoadedMedia) {
              player->play();
          }
      }
      

      this looks a bit strange because same code works fine in a separate application like:

      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
      
          QWidget *widget = new QWidget;
          widget->resize(400, 300);
          QVBoxLayout *layout = new QVBoxLayout;
          QMediaPlayer *player = new QMediaPlayer;
          QVideoWidget *vw = new QVideoWidget;
          layout->addWidget(vw);
          widget->setLayout(layout);
          player->setVideoOutput(vw);
          player->setMedia(QUrl::fromLocalFile("/Users/me/Desktop/VIDEO_TEST/video.mp4"));
          player->setVolume(50);
          player->play();
          widget->show();
          qDebug() << "mediaStatus: " << player->mediaStatus() << "error: " << player->error();
      
          return app.exec();
      }
      
      

      Thanks in advanced
      GG

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @GGAllin last edited by

        @GGAllin You don't call

        video->show();
        

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • GGAllin
          GGAllin last edited by

          thanks for reply
          but show() is called externally (when new VideoPlayer() is called)

          1 Reply Last reply Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            Hi
            So /Users/me/Desktop/VIDEO_TEST/video.mp4 does work in
            other code, on same pc ?

            GGAllin 1 Reply Last reply Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              Hi,

              Why are you calling stop in your custom widget constructor rather that play ?

              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 Reply Quote 0
              • GGAllin
                GGAllin @mrjj last edited by

                @mrjj doesn't work just on VideoPlayer.cpp
                VideoPlayer.cpp doesn't work on OSx and Win, but on Linux work perfectly after installation of gstreamer0.10-ffmpeg

                here works perfectly

                int main(int argc, char **argv)
                {
                    QApplication app(argc, argv);
                
                    QWidget *widget = new QWidget;
                    widget->resize(400, 300);
                    QVBoxLayout *layout = new QVBoxLayout;
                    QMediaPlayer *player = new QMediaPlayer;
                    QVideoWidget *vw = new QVideoWidget;
                    layout->addWidget(vw);
                    widget->setLayout(layout);
                    player->setVideoOutput(vw);
                    player->setMedia(QUrl::fromLocalFile("/Users/me/Desktop/VIDEO_TEST/video.mp4"));
                    player->setVolume(50);
                    player->play();
                    widget->show();
                    qDebug() << "mediaStatus: " << player->mediaStatus() << "error: " << player->error();
                
                    return app.exec();
                }
                

                @SGaist : i changed from stop to play in my contructor, but nothing's changed
                ps: sorry for my bad english!

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  Works fine on macOS, just change the path for the video.

                  #include <QApplication>
                  #include <QWidget>
                  #include <QVBoxLayout>
                  
                  #include <QMediaPlayer> 
                  #include <QVideoWidget>
                  
                  class Widget : public QWidget
                  {
                  public:
                      Widget(QWidget *parent = 0)
                          : QWidget(parent)
                      {
                          QVBoxLayout *layout = new QVBoxLayout(this);
                          QMediaPlayer *player = new QMediaPlayer(this);
                          QVideoWidget *vw = new QVideoWidget;
                          layout->addWidget(vw);
                          player->setVideoOutput(vw);
                          player->setMedia(QUrl::fromLocalFile("/path/to/file"));
                          player->setVolume(50);
                          player->play();
                      }
                  };
                  
                  int main(int argc, char **argv)
                  {
                      QApplication app(argc, argv);
                  
                      Widget widget;
                      widget.resize(400, 300);
                      widget.show();
                  
                      return app.exec();
                  }
                  

                  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 Reply Quote 0
                  • First post
                    Last post