Why does QMediaPlayer play a playlist with setMedia() but not with setPlaylist()?
-
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. :)
-
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. -
@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.
-
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.@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.
-
But when you call
setPlaylist
the playlist is not loaded yet.
How about callsetPlaylist
andplay
after QMediaPlaylist::loaded() is emitted?@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...
-
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.