summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Strømme <christian.stromme@digia.com>2014-06-04 22:30:05 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-06-05 23:25:23 +0200
commit8a66559e0b7d94d6b2ffe613b61194407031730c (patch)
tree0bf6026aa683b2ce849d3f29a16959fea9401ce8
parentd71aaca893a27a8a9a6712a59313300b87226a4f (diff)
downloadqtmultimedia-8a66559e0b7d94d6b2ffe613b61194407031730c.tar.gz
Android: Use a file descriptor for all local media files.
Using a fd is more consistent across different Android versions and also works with files that are in the applications private storage. Task-number: QTBUG-39346 Change-Id: I462822459d12d7842d15f1cb7caafc75c18fe32c Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
-rw-r--r--src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java15
-rw-r--r--src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp2
2 files changed, 11 insertions, 6 deletions
diff --git a/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java b/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java
index 32d3496ee..ff92af771 100644
--- a/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java
+++ b/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java
@@ -379,6 +379,7 @@ public class QtAndroidMediaPlayer
mMediaPlayer.setDisplay(mSurfaceHolder);
AssetFileDescriptor afd = null;
+ FileInputStream fis = null;
try {
mUri = Uri.parse(path);
final boolean inAssets = (mUri.getScheme().compareTo("assets") == 0);
@@ -390,8 +391,8 @@ public class QtAndroidMediaPlayer
final long length = afd.getLength();
FileDescriptor fd = afd.getFileDescriptor();
mMediaPlayer.setDataSource(fd, offset, length);
- } else if (mUri.getScheme().compareTo("tempfile") == 0) {
- FileInputStream fis = new FileInputStream(mUri.getPath());
+ } else if (mUri.getScheme().compareTo("file") == 0) {
+ fis = new FileInputStream(mUri.getPath());
FileDescriptor fd = fis.getFD();
mMediaPlayer.setDataSource(fd);
} else {
@@ -409,9 +410,13 @@ public class QtAndroidMediaPlayer
} catch (final NullPointerException e) {
Log.d(TAG, "" + e.getMessage());
} finally {
- if (afd !=null) {
- try { afd.close(); } catch (final IOException ioe) { /* Ignore... */ }
- }
+ try {
+ if (afd != null)
+ afd.close();
+ if (fis != null)
+ fis.close();
+ } catch (final IOException ioe) { /* Ignore... */ }
+
if ((mState & State.Initialized) == 0) {
setState(State.Error);
onErrorNative(MediaPlayer.MEDIA_ERROR_UNKNOWN,
diff --git a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp
index 6565b0545..6817d65b0 100644
--- a/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp
+++ b/src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp
@@ -312,7 +312,7 @@ void QAndroidMediaPlayerControl::setMedia(const QMediaContent &mediaContent,
const QString path = url.toString().mid(3);
mTempFile.reset(QTemporaryFile::createNativeFile(path));
if (!mTempFile.isNull())
- mediaPath = QLatin1String("tempfile://") + mTempFile->fileName();
+ mediaPath = QStringLiteral("file://") + mTempFile->fileName();
} else {
mediaPath = url.toString();
}