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>
This commit is contained in:
committed by
The Qt Project
parent
5e7e8e04d1
commit
6c941c6c2b
@@ -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);
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user