diff options
author | Christian Strømme <christian.stromme@digia.com> | 2013-05-29 02:06:16 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-09 14:46:49 +0200 |
commit | 6c941c6c2b547c8c1f5dab5310f165e0d796fe96 (patch) | |
tree | 0b58412ae51704b5ab1af7cf9b53b3b46caefbb6 | |
parent | 5e7e8e04d1be82e23f69e2966d355b4aa8d93442 (diff) | |
download | qtmultimedia-6c941c6c2b547c8c1f5dab5310f165e0d796fe96.tar.gz |
Android: Make it possible for MediaPlayer to read from assets.
The Android MediaPlayer doesn't handle assets automatically, so we need to
open it and pass it in as a file descriptor.
Task-number: QTBUG-31422
Change-Id: Ic29c0ab6348d760cf21aa89ae423d41e15523976
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
-rw-r--r-- | src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java | 15 |
1 files changed, 14 insertions, 1 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 e4dbae632..d1abf658e 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 @@ -50,6 +50,9 @@ import android.content.Context; import android.media.MediaPlayer; import android.net.Uri; import android.util.Log; +import java.io.FileDescriptor; +import android.content.res.AssetFileDescriptor; +import android.content.res.AssetManager; public class QtAndroidMediaPlayer extends MediaPlayer { @@ -335,7 +338,17 @@ public class QtAndroidMediaPlayer extends MediaPlayer mPreparing = true; onMediaPlayerInfoNative(MEDIA_PLAYER_PREPARING, 0, mID); mUri = Uri.parse(path); - setDataSource(mApplicationContext, mUri); + if (mUri.getScheme().compareTo("assets") == 0) { + final String asset = mUri.getPath().substring(1 /* Remove first '/' */); + final AssetManager am = mApplicationContext.getAssets(); + final AssetFileDescriptor afd = am.openFd(asset); + final long offset = afd.getStartOffset(); + final long length = afd.getLength(); + FileDescriptor fd = afd.getFileDescriptor(); + setDataSource(fd, offset, length); + } else { + setDataSource(mApplicationContext, mUri); + } mInitialized = true; setOnPreparedListener(new MediaPlayerPreparedListener()); prepareAsync(); |