Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Phonon - issue playing video using iodevice object
Below is the code I am using to play a video
QFile* file =new QFile("C:\Users\jolson\Documents\Test Video\Video\test.avi");
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
Are there additional initilization steps required when using an iodevice? Ultimately my code will be using a custom iodevice which is not working as well.
this is the official solution:
Phonon::MediaSource source(filename); //filename as QString !
Your first solution is not good, because the Phonon::MediaSource needs QString and not a QFile.
Phonon::mediaSource supports IOdevice,URL ...
Maybe I'm wrong, but as I know:
QUrl is not a QString, and QIODevice is not a QFile...
I guess the question is what is the QString used for? If I use QFile-FileName is Media source using the QFile object or is it creating a buffer on its own?
What is required for the media source to use a custom IODevice on windows
This is used with filesystem-filename AND qt-resource-filename:
MediaSource::MediaSource ( const QString & fileName )
This is used when you have an unknown fileformat:
MediaSource::MediaSource ( QIODevice * ioDevice )
In this case you must subclass your format.
But AVI files supported in all platforms, so you don't have to use it.
Here you can find som useful information:
My sample uses AVI, however I will be using an encrypted file that will require that I subclass IODevice. So, under windows the document states I need to use filename. If my class returns the filename , will mediasource use my buffer for reading? How does it use the fileName?
With my current custom class when attempting to play it does read from the buffer but fails after the first few reads.
[quote author="jolson" date="1328116255"]will mediasource use my buffer for reading? How does it use the fileName?
Under Windows the IODevice use QFile in the "deep".
broadpeak - QFile is a subclass of QIODevice , so QFile is a QIODevice
Yes, QFile is a QIODevice, but the QIODEvice is not a QFile.
Object hierarchy is not a two-way street. And the MediaSource is waiting QIODevice.
Anyway you can downcast the device to a file, but this is not a too good solution in this case...
And: "IODevice use QFile" this is only a composition not a inheritance. In function/method parameters you can use only inherited parameter and not a "composited" parameter.
I was able to get Qfile to work. I'm not sure exactly why but the video played when I passed a string not qfile,using a different media file it worked. I havn't checked but my guess is the file that is named .avi isn't an avi file.
Anyway I still have a problem with the QIO device class I created. What's happening when I call play is my readData method is called several times (enough to read about 2 seconds of video). The video is never displayed and data is no longer read.
Ok, one more thing I hate to bring this up Yes -QFile is a QIODevice, but the QIODEvice is not a QFile. Correct and if mediasource was expecting QFile I could not pass a QIODevice. QIODevice is an abstract class as such the only way for me to pass a QIODevice is with a class that extends it - QFile or my own custom device.