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. QMediaPlayer / QVideoWidget do not show

QMediaPlayer / QVideoWidget do not show

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 3.4k Views
  • 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.
  • GGAllinG Offline
    GGAllinG Offline
    GGAllin
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • GGAllinG GGAllin

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @GGAllin You don't call

      video->show();
      

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

      1 Reply Last reply
      0
      • GGAllinG Offline
        GGAllinG Offline
        GGAllin
        wrote on last edited by
        #3

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

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

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

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

            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
            0
            • mrjjM mrjj

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

              GGAllinG Offline
              GGAllinG Offline
              GGAllin
              wrote on last edited by
              #6

              @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
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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
                0

                • Login

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