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");
    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:\Users\jolson\Documents\Test Video\Video\test.avi"));
    media->play();

    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.

    thanks



  • this is the official solution:

    Phonon::MediaObject localMediaObject;
    Phonon::MediaSource source(filename); //filename as QString !
    localMediaObject.setCurrentSource(source);

    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:
    http://developer.qt.nokia.com/doc/qt-4.8/phonon-mediasource.html#MediaSource



  • 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?
    [/quote]

    Yes.
    Under Windows the IODevice use QFile in the "deep".



  • broadpeak - QFile is a subclass of QIODevice , so QFile is a QIODevice



  • IMHO:
    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.