Android: Fix loading from qrc
authorChristian Strømme <christian.stromme@digia.com>
Fri, 16 May 2014 12:53:13 +0000 (14:53 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 20 May 2014 22:14:15 +0000 (00:14 +0200)
On Android < 4.1 our temporary file is discarded without checking the
content. With this change we just open the file and pass the fd to the
mediaplayer instead.

Change-Id: I9233822725d8987c572b2d0b598721cee886de80
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java
src/plugins/android/src/mediaplayer/qandroidmediaplayercontrol.cpp

index 86ec30a..01f2609 100644 (file)
@@ -43,6 +43,7 @@ package org.qtproject.qt5.android.multimedia;
 
 import java.io.IOException;
 import java.lang.String;
+import java.io.FileInputStream;
 
 // API is level is < 9 unless marked otherwise.
 import android.app.Activity;
@@ -387,6 +388,10 @@ 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());
+                FileDescriptor fd = fis.getFD();
+                mMediaPlayer.setDataSource(fd);
             } else {
                 mMediaPlayer.setDataSource(mActivity, mUri);
             }
index 23ffb32..68fb5e4 100644 (file)
@@ -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("file://") + mTempFile->fileName();
+            mediaPath = QLatin1String("tempfile://") + mTempFile->fileName();
     } else {
         mediaPath = url.toString();
     }