Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-121355

Setting QMediaPlayer's source to the same value when mediaStatus is EndOfMedia and pressing play does not start media again from the beginning

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.6.1
    • Multimedia
    • None
    • openSUSE Tumbleweed 20240110
      Using Qt version 6.6.1 in /usr/lib64
    • Linux/X11

    Description

      Run the following code

      #include <QCoreApplication>
      #include <QMediaPlayer>
      #include <QAudioOutput>
      #include <QTimer>
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
          auto *audioOutput = new QAudioOutput{};
          auto *mediaPlayer = new QMediaPlayer{};
          mediaPlayer->setAudioOutput(audioOutput);
          const QUrl mediaSource{QStringLiteral("file:///path/to/shortMediaFile.mp3")};
          mediaPlayer->setSource(mediaSource);
          mediaPlayer->play();
          QObject::connect(mediaPlayer, &QMediaPlayer::mediaStatusChanged, mediaPlayer, [mediaPlayer, mediaSource]() {
              if (mediaPlayer->mediaStatus() == QMediaPlayer::EndOfMedia) {
                  qInfo() << "Media ended" << mediaPlayer->mediaStatus() << mediaPlayer->playbackState() << mediaPlayer->position();
                  mediaPlayer->setSource(mediaSource);
                  qInfo() << "set source" << mediaPlayer->mediaStatus() << mediaPlayer->playbackState() << mediaPlayer->position();
                  // mediaPlayer->setPosition(0); // uncomment to make things work
                  // qInfo() << "set position" << mediaPlayer->mediaStatus() << mediaPlayer->playbackState() << mediaPlayer->position();
                  mediaPlayer->play();
                  qInfo() << "set play" << mediaPlayer->mediaStatus() << mediaPlayer->playbackState() << mediaPlayer->position();
              }
          });
          return app.exec();
      }
      

      The media only plays once and the output is this (repeats):

      GPU at BusId 0x8 doesn't have a supported video decoder
      [mjpeg_cuvid @ 0x592900] Codec mjpeg_cuvid is not supported.
      Media ended QMediaPlayer::EndOfMedia QMediaPlayer::StoppedState 10582
      set source QMediaPlayer::LoadedMedia QMediaPlayer::StoppedState 0
      [mjpeg_cuvid @ 0x5d1f80] Codec mjpeg_cuvid is not supported.
      set play QMediaPlayer::BufferedMedia QMediaPlayer::PlayingState 0
      Media ended QMediaPlayer::EndOfMedia QMediaPlayer::StoppedState 10582
      set source QMediaPlayer::LoadedMedia QMediaPlayer::StoppedState 0
      [mjpeg_cuvid @ 0x5d1f80] Codec mjpeg_cuvid is not supported.
      set play QMediaPlayer::BufferedMedia QMediaPlayer::PlayingState 0
      

      Usually I would expect the playback to start from the beginning, as this is what happens when setting the source & calling play for other media statuses (e.g. QMediaPlayer::Buffered). This is also what happens when setting a new source when the mediaStatus is EndOfMedia

      I would also say that setting the source to the same value can be a bit ambiguous, and personally I wasn't sure what to expect when trying this. I think that this special case should be documented in the QMediaPlayer source property so that people doing stuff like this know exactly what the expected behaviour is.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qtmultimediateam Qt Multimedia Team
            jackh Jack Hill
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes