summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/MediaMetadataRetriever.java20
-rw-r--r--media/java/android/media/MediaPlayer.java23
-rw-r--r--media/jni/android_media_MediaMetadataRetriever.cpp9
-rw-r--r--media/jni/android_media_MediaPlayer.cpp8
4 files changed, 39 insertions, 21 deletions
diff --git a/media/java/android/media/MediaMetadataRetriever.java b/media/java/android/media/MediaMetadataRetriever.java
index 11ecd1f..aef631f 100644
--- a/media/java/android/media/MediaMetadataRetriever.java
+++ b/media/java/android/media/MediaMetadataRetriever.java
@@ -23,6 +23,7 @@ import android.graphics.Bitmap;
import android.net.Uri;
import java.io.FileDescriptor;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -57,7 +58,24 @@ public class MediaMetadataRetriever
* @param path The path of the input media file.
* @throws IllegalArgumentException If the path is invalid.
*/
- public native void setDataSource(String path) throws IllegalArgumentException;
+ public void setDataSource(String path) throws IllegalArgumentException {
+ FileInputStream is = null;
+ try {
+ is = new FileInputStream(path);
+ FileDescriptor fd = is.getFD();
+ setDataSource(fd, 0, 0x7ffffffffffffffL);
+ } catch (FileNotFoundException fileEx) {
+ throw new IllegalArgumentException();
+ } catch (IOException ioEx) {
+ throw new IllegalArgumentException();
+ }
+
+ try {
+ if (is != null) {
+ is.close();
+ }
+ } catch (Exception e) {}
+ }
/**
* Sets the data source (URI) to use. Call this
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index c38f8f3..dd01db6 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_MediaMetadataRetriever.cpp b/media/jni/android_media_MediaMetadataRetriever.cpp
index 0dc3b65..297dadf 100644
--- a/media/jni/android_media_MediaMetadataRetriever.cpp
+++ b/media/jni/android_media_MediaMetadataRetriever.cpp
@@ -131,13 +131,6 @@ android_media_MediaMetadataRetriever_setDataSourceAndHeaders(
"setDataSource failed");
}
-
-static void android_media_MediaMetadataRetriever_setDataSource(
- JNIEnv *env, jobject thiz, jstring path) {
- android_media_MediaMetadataRetriever_setDataSourceAndHeaders(
- env, thiz, path, NULL, NULL);
-}
-
static void android_media_MediaMetadataRetriever_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
{
ALOGV("setDataSource");
@@ -447,8 +440,6 @@ static void android_media_MediaMetadataRetriever_native_setup(JNIEnv *env, jobje
// JNI mapping between Java methods and native methods
static JNINativeMethod nativeMethods[] = {
- {"setDataSource", "(Ljava/lang/String;)V", (void *)android_media_MediaMetadataRetriever_setDataSource},
-
{
"_setDataSource",
"(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V",
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index 2e74ffd..5eadb3a 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",