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

Commit f3d9f5d0 authored by James Dong's avatar James Dong Committed by Android (Google) Code Review
Browse files

Merge "Fix failure from setDataSource(String path) when path is a local file"

parents 793807ff e00b6f3a
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",