Android: Fix loading from qrc

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>
This commit is contained in:
Christian Strømme
2014-05-16 14:53:13 +02:00
committed by The Qt Project
parent 93e73fd8ee
commit 7e668fe58f
2 changed files with 6 additions and 1 deletions

View 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);
}

View 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();
}