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

Cannot play a media file stored on temp location on Android

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.3.0
    • Fix Version/s: 5.3.1
    • Component/s: Multimedia
    • Labels:
      None
    • Platform/s:
      Android
    • Commits:
      8a66559e0b7d94d6b2ffe613b61194407031730c

      Description

      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:
      file:///data/data/com.totape.totapedev/cache/record.mp4

      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:

      fileToPlay->setFileName(url.toLocalFile());
      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:

      fileToPlay->close();
      fileToPlay->setFileName(url.toLocalFile());
      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)

        Attachments

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

          Activity

            People

            Assignee:
            stromme Christian
            Reporter:
            gianluca Gianluca Massera
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes