diff options
author | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-01-21 16:44:40 +0100 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-02-12 15:07:25 +0100 |
commit | cbdf4561f5cdb6ee95583f14a3769c3124228586 (patch) | |
tree | 912b4b19c0001e7611f64fae87091b87d2071e0e /src/multimedia | |
parent | e47ed7b88223c42dd20ef86b829061fcc4f1fc30 (diff) |
Android: Flush qrc to tmp file with original name
Since android.media.MediaPlayer does not support playing from data stream,
we create a temporary file and copy data to it.
Each such file contains unique name.
When the app is killed, dtor of QMediaPlayer is not called and thus
the temporary file is not deleted.
Also these files are located inside app's location, e.g.
/data/data/org.qtproject.example.app/files/, and no possibility to delete
them automatically.
Added a fix to rename the temporary file to original name which allows to keep
only one copy of the file when the app is killed.
Change-Id: I36c8bc4dd339fbf4091689a05f4d9c7febf046a5
Fixes: QTBUG-59517
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/playback/qmediaplayer.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp index 48db0335e..cd27d3b1d 100644 --- a/src/multimedia/playback/qmediaplayer.cpp +++ b/src/multimedia/playback/qmediaplayer.cpp @@ -366,6 +366,13 @@ void QMediaPlayerPrivate::setMedia(const QMediaContent &media, QIODevice *stream control->setMedia(media, file.data()); } else { #if QT_CONFIG(temporaryfile) +#if defined(Q_OS_ANDROID) + QString tempFileName = QDir::tempPath() + media.request().url().path(); + QDir().mkpath(QFileInfo(tempFileName).path()); + QTemporaryFile *tempFile = QTemporaryFile::createNativeFile(*file); + if (!tempFile->rename(tempFileName)) + qWarning() << "Could not rename temporary file to:" << tempFileName; +#else QTemporaryFile *tempFile = new QTemporaryFile; // Preserve original file extension, some backends might not load the file if it doesn't @@ -384,7 +391,7 @@ void QMediaPlayerPrivate::setMedia(const QMediaContent &media, QIODevice *stream tempFile->write(buffer, len); } tempFile->close(); - +#endif file.reset(tempFile); control->setMedia(QMediaContent(QUrl::fromLocalFile(file->fileName())), nullptr); #else |