Playing media from QIODevice and nothing else
Posted: Sun Jun 26 2022 3:14 pm
I am working on an application that has its music files in Ogg format embedded in its own containers. I can 'open' those files and present them as a QIODevice *. I then want to play them using QMediaPlayer but that simply refuses to play anything that does not have a valid URL, which is a bit counter to what the documentation of QMediaPlayer::setMedia says:
I have tried may things for the QMediaContent, the QUrl and mime-type, but it will only play audio when QUrl points to something it can open. I tried 'null', no string, empty string, 'file://', et cetera. Typical error message is:
Often if does not even print this or emit the MediaPlayer mediaStatusChanged signal. So, any suggestions on how to get the QMediaPlayer to behave?
I am setting the MIME type explicitly:Sets the current media source.
If a stream is supplied, media data will be read from it instead of resolving the media source. In this case the media source may still be used to resolve additional information about the media such as mime type. The stream must be open and readable.
Code: Select all
QIODevice *m_input = openContainer("1.ogg");
QMediaResource resource (QUrl (), "audio/ogg");
QMediaContent content (resource);
qDebug() << "isNull" << content.isNull(); // is false, by the way
m_player.setMedia (content, m_input);
m_player.play ();
Code: Select all
isNull false
GStreamer; Unable to pause -
Player::newMediaStatus: 2
GStreamer; Unable to pause -
Player::newMediaStatus: 8
Error: Invalid URI "".