summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author James Dong <jdong@google.com> 2012-04-11 21:18:43 -0700
committer James Dong <jdong@google.com> 2012-04-12 11:50:17 -0700
commite00b6f3a57d4b480ce674468de93555269bbd71a (patch)
treeab8e8174ddb140ad8994e6bf70a50430e7c18150
parent54ae14749bc7f9e73cfda35a8b49f9efa80a77fb (diff)
Fix failure from setDataSource(String path) when path is a local file
o the failure was because the mediaserver does not have read permission to sdcard o related-to-bug: 6325960,6322913 Change-Id: I4feec01b8165c78563eee8aab69cb24df3244d03
-rw-r--r--media/java/android/media/MediaPlayer.java23
-rw-r--r--media/jni/android_media_MediaPlayer.cpp8
2 files changed, 20 insertions, 11 deletions
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index c38f8f35a2bf..dd01db6fd29b 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -34,7 +34,9 @@ import android.graphics.Bitmap;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
+import java.io.File;
import java.io.FileDescriptor;
+import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Map;
@@ -847,8 +849,10 @@ public class MediaPlayer
* As an alternative, the application could first open the file for reading,
* and then use the file descriptor form {@link #setDataSource(FileDescriptor)}.
*/
- public native void setDataSource(String path)
- throws IOException, IllegalArgumentException, SecurityException, IllegalStateException;
+ public void setDataSource(String path)
+ throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
+ setDataSource(path, null, null);
+ }
/**
* Sets the data source (file-path or http/rtsp URL) to use.
@@ -875,7 +879,20 @@ public class MediaPlayer
++i;
}
}
- _setDataSource(path, keys, values);
+ setDataSource(path, keys, values);
+ }
+
+ private void setDataSource(String path, String[] keys, String[] values)
+ throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
+ File file = new File(path);
+ if (file.exists()) {
+ FileInputStream is = new FileInputStream(file);
+ FileDescriptor fd = is.getFD();
+ setDataSource(fd);
+ is.close();
+ } else {
+ _setDataSource(path, keys, values);
+ }
}
private native void _setDataSource(
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 2e74ffd8b3d5..5eadb3a9c1d4 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -216,12 +216,6 @@ android_media_MediaPlayer_setDataSourceAndHeaders(
}
static void
-android_media_MediaPlayer_setDataSource(JNIEnv *env, jobject thiz, jstring path)
-{
- android_media_MediaPlayer_setDataSourceAndHeaders(env, thiz, path, NULL, NULL);
-}
-
-static void
android_media_MediaPlayer_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
{
sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
@@ -825,8 +819,6 @@ android_media_MediaPlayer_setNextMediaPlayer(JNIEnv *env, jobject thiz, jobject
// ----------------------------------------------------------------------------
static JNINativeMethod gMethods[] = {
- {"setDataSource", "(Ljava/lang/String;)V", (void *)android_media_MediaPlayer_setDataSource},
-
{
"_setDataSource",
"(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V",