Skip to content

Commit 0041b5c

Browse files
author
James Dong
committed
Fix thumbnail generation failure
o Change the impl of MediaMetadataRetriever.setDataSource(String). It opens and passes an fd to the media framework rather than pass the file path directly to the media server. The change is needed since media server does not have read permission to sdcard o Remove the unnecessary jni method Change-Id: I5a2f47dde804523d264b588f855ba2575a99c179
1 parent 54ae147 commit 0041b5c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

media/java/android/media/MediaMetadataRetriever.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.net.Uri;
2424

2525
import java.io.FileDescriptor;
26+
import java.io.FileInputStream;
2627
import java.io.FileNotFoundException;
2728
import java.io.IOException;
2829

@@ -57,7 +58,24 @@ public MediaMetadataRetriever() {
5758
* @param path The path of the input media file.
5859
* @throws IllegalArgumentException If the path is invalid.
5960
*/
60-
public native void setDataSource(String path) throws IllegalArgumentException;
61+
public void setDataSource(String path) throws IllegalArgumentException {
62+
FileInputStream is = null;
63+
try {
64+
is = new FileInputStream(path);
65+
FileDescriptor fd = is.getFD();
66+
setDataSource(fd, 0, 0x7ffffffffffffffL);
67+
} catch (FileNotFoundException fileEx) {
68+
throw new IllegalArgumentException();
69+
} catch (IOException ioEx) {
70+
throw new IllegalArgumentException();
71+
}
72+
73+
try {
74+
if (is != null) {
75+
is.close();
76+
}
77+
} catch (Exception e) {}
78+
}
6179

6280
/**
6381
* Sets the data source (URI) to use. Call this

media/jni/android_media_MediaMetadataRetriever.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,6 @@ android_media_MediaMetadataRetriever_setDataSourceAndHeaders(
131131
"setDataSource failed");
132132
}
133133

134-
135-
static void android_media_MediaMetadataRetriever_setDataSource(
136-
JNIEnv *env, jobject thiz, jstring path) {
137-
android_media_MediaMetadataRetriever_setDataSourceAndHeaders(
138-
env, thiz, path, NULL, NULL);
139-
}
140-
141134
static void android_media_MediaMetadataRetriever_setDataSourceFD(JNIEnv *env, jobject thiz, jobject fileDescriptor, jlong offset, jlong length)
142135
{
143136
ALOGV("setDataSource");
@@ -447,8 +440,6 @@ static void android_media_MediaMetadataRetriever_native_setup(JNIEnv *env, jobje
447440

448441
// JNI mapping between Java methods and native methods
449442
static JNINativeMethod nativeMethods[] = {
450-
{"setDataSource", "(Ljava/lang/String;)V", (void *)android_media_MediaMetadataRetriever_setDataSource},
451-
452443
{
453444
"_setDataSource",
454445
"(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V",

0 commit comments

Comments
 (0)