How to use the multimedia module in Qt6 to play network media that requires http headers to be set
-
Hi, I'm a QT beginner. I want to try to use QMediaPlayer to play web media that may require setting HTTP headers such as cookies.
I found that I can use QMediaPlayer::setMedia in Qt5 to solve the problem. But QMediaContent has been removed in Qt6, how do I implement similar functionality in Qt6? -
Hi and welcome to devnet,
Can your show how you are doing it with Qt 5 ?
-
@SGaist
Maybe like thisQMediaPlayer player; QNetworkRequest req(QUrl("https://example.com/xxx.mp3")); req.setRawHeader("Cookie", "uid=123456"); player.setMedia(req); player.play();
I don't have the Qt5.X SDK installed on my computer and haven't verified that the code is available
-
In Qt6, there's no version of setSource() that takes a network request like setMedia() in Qt5. It might work if you add a QUrlQuery to your QUrl; e.g.
QMediaPlayer player; QUrl mediaUrl("https://example.com/xxx.mp3"); mediaUrl.setQuery({"uid", "123456"}); player.setSource(mediaUrl); player.play();