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

Commit a3a45e40 authored by Hui (QRD) Yu's avatar Hui (QRD) Yu Committed by Ricardo Cerqueira
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 8aefad60
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -3067,6 +3067,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();

    /** @hide */
    static class TimeProvider implements MediaPlayer.OnSeekCompleteListener,
            MediaTimeProvider {
+34 −0
Original line number Diff line number Diff line
@@ -858,6 +858,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 JNINativeMethod gMethods[] = {
@@ -902,6 +934,8 @@ static JNINativeMethod gMethods[] = {
    {"native_pullBatteryData", "(Landroid/os/Parcel;)I",        (void *)android_media_MediaPlayer_pullBatteryData},
    {"native_setRetransmitEndpoint", "(Ljava/lang/String;I)I",  (void *)android_media_MediaPlayer_setRetransmitEndpoint},
    {"setNextMediaPlayer",  "(Landroid/media/MediaPlayer;)V",   (void *)android_media_MediaPlayer_setNextMediaPlayer},
    {"_suspend",             "()Z",                             (void *)android_media_MediaPlayer_suspend},
    {"_resume",              "()Z",                             (void *)android_media_MediaPlayer_resume},
};

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