Search code examples
c++qtphonon

QT phonon playback is failing when a QFILE is used for mediaSource, works fine when a string is passed


Below is the code I am using to play a video

 QFile* file =new QFile(“C:\\Video\\test.avi”);
   media->setCurrentSource(Phonon::MediaSource(file));
   media->play();

Using this code the playback fails -what I see is the play bar at the bottom but the video never starts.

If I change the code to the following everything works as expected

  media->setCurrentSource(Phonon::MediaSource(“C:\\Video\\test.avi”));
  media->play();

Are there additional initialization steps required when using an iodevice? Ultimately my code will be using a custom iodevice which is not working as well.


Solution

  • This is an old post, but I wanted to clear up any confusion out in case it will help someone in the future.

    1. QT does allow you to pass Phonon::MediaSource() a QIODevice. We successfully deployed our solution by creating our own subclass of QIODevice.

    The reason it was not working for me was QT was having an issue with the codec I was using. When you use the QIO device you don't get the same format support as you would if you pass a string.

    One other thing to note, while this solution works great on windows. On a mac when using the QIO device the entire file will be loaded into memory before it plays. In my case this was a deal breaker. Having an encrypted file is usless if the first thing you do is de-crypt the entire file and load it into memory.