Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Phonon - issue playing video using iodevice object
Forum Updated to NodeBB v4.3 + New Features

Phonon - issue playing video using iodevice object

Scheduled Pinned Locked Moved General and Desktop
12 Posts 2 Posters 4.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jolson
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • B Offline
      B Offline
      broadpeak
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jolson
        wrote on last edited by
        #3

        Phonon::mediaSource supports IOdevice,URL ...

        1 Reply Last reply
        0
        • B Offline
          B Offline
          broadpeak
          wrote on last edited by
          #4

          Maybe I'm wrong, but as I know:
          QUrl is not a QString, and QIODevice is not a QFile...

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jolson
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • B Offline
              B Offline
              broadpeak
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jolson
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  broadpeak
                  wrote on last edited by
                  #8

                  [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".

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jolson
                    wrote on last edited by
                    #9

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

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      broadpeak
                      wrote on last edited by
                      #10

                      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.

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jolson
                        wrote on last edited by
                        #11

                        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.

                        1 Reply Last reply
                        0
                        • J Offline
                          J Offline
                          jolson
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved