Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-39346

Cannot play a media file stored on temp location on Android



    • Bug
    • Status: Closed
    • P2: Important
    • Resolution: Done
    • 5.3.0
    • 5.3.1
    • Multimedia
    • None
    • Android
    • 8a66559e0b7d94d6b2ffe613b61194407031730c


      Suppose to record an audio file on Android with QAudioRecorder setting the output location as follow:

      QString tempLocation = QStandardPaths::writableLocation( QStandardPaths::TempLocation );
      recorder->setOutputLocation( QUrl::fromLocalFile(tempLocation+"/record") );

      The recording cause not problems. And the file is stored on a temp location on android:

      But then, suppose you want to add the possibility to listen what you've just recorded. And then it's come the bug.
      In fact, using the QMediaPlayer setting the mediaContent to the Uri above results in the following error on play:

      E/MediaPlayer(16065): Uri is file:///data/data/com.totape.totapedev/cache/record.mp4
      E/MediaPlayer(16065): error (1, -2147483648)
      E/MediaPlayer(16065): Error (1,-2147483648)

      Searching on internet, I discovered that this problem happens because the underlying Android Player requires that the file going to be played had the world-read permission on. But when you save on the temp location the permission for world-read are off.

      Android documentation suggests to solve this problem passing directly an opened file stream to the player instead of the Uri location of the file. In this way, the permission problems are bypassed because the file is opened by the app itself and the android player just read from the file stream opened.

      So, looking into the Qt documentation I found that there is an undocumented method of QMediaPlayer that allow me to pass an QIODevice. I was supposing that it was there to solve problems like that. But it does not work.

      I tried in this way:

      bool isopen = fileToPlay->open( QIODevice::ReadOnly );
      qDebug() << "PASSING THE QIODEVICE" << isopen;
      player->setMedia(content, fileToPlay);

      where content is a QMediaContent pointing to the location of the recorded file.
      And in this way:

      bool isopen = fileToPlay->open( QIODevice::ReadOnly );
      qDebug() << "PASSING THE QIODEVICE" << isopen;
      player->setMedia(QMediaContent(), fileToPlay);

      where I used an empty QMediaContent.

      Both solution still continue to give me the same error above:

      E/MediaPlayer(16706): Uri is file:///data/data/com.totape.totapedev/cache/record.mp4
      E/MediaPlayer(16706): error (1, -2147483648)
      D/Qt (16706): ../../Projects/totape/totapeQt/backend.cpp:144 (void Backend::setMediaToPlay(QString, QObject*)): PASSING THE QIODEVICE true
      E/MediaPlayer(16706): Error (1,-2147483648)


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            stromme Christian
            gianluca Gianluca Massera
            0 Vote for this issue
            2 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes