[Interest] How do use QMediaPlayer on a QIODevice?

Nikos Chantziaras realnc at gmail.com
Sat Jun 8 12:41:51 CEST 2013


QMediaPlayer is unable to play anything, be it video or audio, from a 
QIODevice.  Even this simple example fails:

   QMediaPlayer* player =
     new QMediaPlayer(0, QMediaPlayer::StreamPlayback);

   QFile* file = new QFile("/tmp/audio.ogg");
   if (not file->open(QFile::ReadOnly)) {
       abort();
   }
   player->setMedia(QUrl(), file);
   player->play();

It doesn't play, and this is printed on stderr:

   Error: "Could not demultiplex stream."

This, on the other hand, works:

   QMediaPlayer* player = new QMediaPlayer;
   player->setMedia(QUrl::fromLocalFile("/tmp/audio.ogg"));
   player->play();

If I try the same with a video, the error is:

   Warning: "Could not demultiplex stream."
   Error: "No valid frames found before end of stream"

I also tried omitting QMediaPlayer::StreamPlayback from the ctor, but it 
doesn't change anything.  I also found a bug that looks exactly like the 
problem I'm having, but it was closed as fixed long ago:

   https://bugreports.qt-project.org/browse/QTMOBILITY-1421

I'm using Qt 5.1.0 beta on Gentoo Linux AMD64.  GStreamer version is 
0.10.36 and gst-plugins-base is installed (in particular, it provides 
/usr/lib64/gstreamer-0.10/libgstapp.so).

How do I get this work?




More information about the Interest mailing list