Suppose to record an audio file on Android with QAudioRecorder setting the output location as follow:
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:
where content is a QMediaContent pointing to the location of the recorded file.
And in this way:
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)
|For Gerrit Dashboard: QTBUG-39346|
|86815,2||Android: Use a file descriptor for all local media files.||stable||qt/qtmultimedia||Status: MERGED||+2||0|