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

Commit 820486e1 authored by Hui (QRD) Yu's avatar Hui (QRD) Yu Committed by Steve Kondik
Browse files

Add 2 APIs (suspend/resume) in MediaPlayer

- API:suspend() will just pause the player and release all the decoders
  to replace release() which will release the whole player
- API:resume() will just init the decoders again,
  then start() will be called to start to play the streaming

Change-Id: I3e2ffeb50dfe6d156b18416fa8964ff4a3d56a2c
parent f8f1aa49
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -2741,6 +2741,23 @@ public class MediaPlayer implements SubtitleController.Listener
                mode == VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
    }

    /** @hide
    */
    public boolean suspend() {
        stayAwake(false);
        return _suspend();
    }

    private native boolean _suspend();

    /** @hide
    */
    public boolean resume() {
        return _resume();
    }

    private native boolean _resume();

    private Context mProxyContext = null;
    private ProxyReceiver mProxyReceiver = null;

+34 −0
Original line number Diff line number Diff line
@@ -812,6 +812,38 @@ android_media_MediaPlayer_setNextMediaPlayer(JNIEnv *env, jobject thiz, jobject
    ;
}

static jboolean
android_media_MediaPlayer_suspend(JNIEnv *env, jobject thiz)
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return false;
    }

    if (mp->suspend() != OK) {
        return false;
    }

    return true;
}

static jboolean
android_media_MediaPlayer_resume(JNIEnv *env, jobject thiz)
{
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return false;
    }

    if (mp->resume() != OK) {
        return false;
    }

    return true;
}

static void
android_media_MediaPlayer_updateProxyConfig(
        JNIEnv *env, jobject thiz, jobject proxyProps)
@@ -897,6 +929,8 @@ static JNINativeMethod gMethods[] = {
    {"native_setRetransmitEndpoint", "(Ljava/lang/String;I)I",  (void *)android_media_MediaPlayer_setRetransmitEndpoint},
    {"setNextMediaPlayer",  "(Landroid/media/MediaPlayer;)V",   (void *)android_media_MediaPlayer_setNextMediaPlayer},
    {"updateProxyConfig", "(Landroid/net/ProxyProperties;)V", (void *)android_media_MediaPlayer_updateProxyConfig},
    {"_suspend",             "()Z",                             (void *)android_media_MediaPlayer_suspend},
    {"_resume",              "()Z",                             (void *)android_media_MediaPlayer_resume},
};

static const char* const kClassPathName = "android/media/MediaPlayer";