Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7420a7cd authored by James Dong's avatar James Dong Committed by The Android Automerger
Browse files

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
parent f715e0fd
Loading
Loading
Loading
Loading
+20 −3
Original line number Diff line number Diff line
@@ -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,8 +879,21 @@ public class MediaPlayer
                ++i;
            }
        }
        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(
        String path, String[] keys, String[] values)
+0 −8
Original line number Diff line number Diff line
@@ -215,12 +215,6 @@ android_media_MediaPlayer_setDataSourceAndHeaders(
            "setDataSource failed." );
}

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)
{
@@ -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",