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

StackOverflow https://stackoverflow.com/questions/9098543

  •  21-04-2021
  •  | 
  •  

Frage

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.

War es hilfreich?

Lösung

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.

Andere Tipps

From the Phonon::MediaSource documentation:

Warning: On Windows, we only support QIODevices containing the avi, mp3, or mpg formats. Use the constructor that takes a file name to open files (the Qt backend does not use a QFile internally).

I think that the last line should answer your question. Instead of a QFile, you can use a QString, or call the function QFile::fileName like this:

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

If you take a careful look in the [Phonon Module docu][1], you will see that MediaSource cannot be constructed with QFile*.

By the way I don't see in your code any phonon paths. At least you should create audio sink and connect it with the mediaobject:

Phonon::AudioOutput *audioOut = new PhononAudioOutpu(Phonon::MusicCategory);//or the      category you need
Phonon::createPath(mediaObject, audioOutput);
mediaObject->play();

Works fine with QFile

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top