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. Why does QMediaPlayer play a playlist with setMedia() but not with setPlaylist()?
Forum Updated to NodeBB v4.3 + New Features

Why does QMediaPlayer play a playlist with setMedia() but not with setPlaylist()?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 1.0k 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.
  • AlveinA Offline
    AlveinA Offline
    Alvein
    wrote on last edited by
    #1

    Hello,

    Let's assume we have video streamed from this URL:

    playListURL="https://example.com/playlist.m3u8";
    

    This code works with no problems**:

    player = new QMediaPlayer;
    player->setMedia(QUrl(playListURL));
    videoWidget = new QVideoWidget;
    player->setVideoOutput(videoWidget);
    videoWidget->show();
    player->play();
    

    But this one does not show anything:

    playlist = new QMediaPlaylist;
    playlist->load(QUrl(playListURL));
    player = new QMediaPlayer;
    player->setPlaylist(playlist);
    videoWidget = new QVideoWidget;
    player->setVideoOutput(videoWidget);
    videoWidget->show();
    player->play();
    

    Am I handling that playlist the right way?

    Additionally, I am aware that inside the original playlist, there are other streams. Internally, there are references to other .m3u8 files, each one for a distinct bitrate and resolution.

    **That's why the first snippet is not enough. I need to choose a given stream from that playlist, and setMedia() is choosing one at random (I am not sure which criteria does it use).

    So how do I load this playlist to be handled as a playlist?

    Thanks. :)

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      https://doc.qt.io/qt-5/qmediaplaylist.html#load-1
      Can you confirm the playlist is loaded correctly? Maybe you need to specify the format if it is not guessing correctly.

      C++ is a perfectly valid school of magic.

      AlveinA 1 Reply Last reply
      1
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Alvein said in Why does QMediaPlayer play a playlist with setMedia() but not with setPlaylist()?:

        playlist->load(QUrl(playListURL));

        Take a look what QMediaPlayList::error() gives you back.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • fcarneyF fcarney

          https://doc.qt.io/qt-5/qmediaplaylist.html#load-1
          Can you confirm the playlist is loaded correctly? Maybe you need to specify the format if it is not guessing correctly.

          AlveinA Offline
          AlveinA Offline
          Alvein
          wrote on last edited by
          #4

          @fcarney Signal QMediaPlaylist::loaded() is emitted.

          About the format...I don't know what to put there. That looks pretty much undocumented.
          Anyway, I've used "m3u", "m3u8", ".m3u" and ".m3u8". Hard to guess and it does not work either.

          @Christian-Ehrlicher QMediaPlaylist::NoError.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bonnie
            wrote on last edited by
            #5

            But when you call setPlaylist the playlist is not loaded yet.
            How about call setPlaylist and play after QMediaPlaylist::loaded() is emitted?

            AlveinA 1 Reply Last reply
            3
            • B Bonnie

              But when you call setPlaylist the playlist is not loaded yet.
              How about call setPlaylist and play after QMediaPlaylist::loaded() is emitted?

              AlveinA Offline
              AlveinA Offline
              Alvein
              wrote on last edited by
              #6

              @Bonnie Thank you. That did the trick. Had to implement something like isLoaded() and isLoading() because the QMediaPlaylist class does not provide a quick way to check if the playlist is ready.

              So far, good. But I still need to get the details of every stream enclosed in the playlist (to let the user pick one).

              Let's use a real case. This:

              playListURL="http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8";
              

              Includes 4 streams according to the m3u8 contents:

              #EXTM3U
              #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000
              gear1/prog_index.m3u8
              #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=311111
              gear2/prog_index.m3u8
              #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=484444
              gear3/prog_index.m3u8
              #EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=737777
              gear4/prog_index.m3u8
              

              How do I get the individual bandwidth values?? The data is right there, evern before having to play anything...

              1 Reply Last reply
              0
              • AlveinA Offline
                AlveinA Offline
                Alvein
                wrote on last edited by Alvein
                #7

                OK. It seems I had an excessive expectation for the QtMultimedia's playlist management.
                According to the source code, just a few directives are handled, so forget about #EXT-X-STREAM-INF.

                Additionally, even after the stream has begun to play, I didn't find a safe way of getting the video details like bitrate, framerate or resolution. Not through QMediaPlayer's metadata, not through QMediaContent's resources.

                There's a "prospect" approach (talk about overkill), through QVideoWidget::videoSurface()::surfaceFormat(), but this thing was introduced in Qt 5.15. I have 5.14 and too lazy to upgrade just to check that.

                In the end, it's way simpler for me to download the playlist and parse the required directives myself.

                1 Reply Last reply
                1

                • Login

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