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

Commit fbb38850 authored by Andreas Huber's avatar Andreas Huber
Browse files

New API on java's MediaPlayer to suspend/resume a session.

related-to-bug: 2231576
parent 965e37ec
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ public:
    virtual status_t        setAudioStreamType(int type) = 0;
    virtual status_t        setLooping(int loop) = 0;
    virtual status_t        setVolume(float leftVolume, float rightVolume) = 0;
    virtual status_t        suspend() = 0;
    virtual status_t        resume() = 0;

    // Invoke a generic method on the player by using opaque parcels
    // for the request and reply.
+3 −0
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ public:
    virtual status_t    reset() = 0;
    virtual status_t    setLooping(int loop) = 0;
    virtual player_type playerType() = 0;
    virtual status_t    suspend() { return INVALID_OPERATION; }
    virtual status_t    resume() { return INVALID_OPERATION; }

    virtual void        setNotifyCallback(void* cookie, notify_callback_f notifyFunc) {
                            mCookie = cookie; mNotify = notifyFunc; }
    // Invoke a generic method on the player by using opaque parcels
+2 −0
Original line number Diff line number Diff line
@@ -165,6 +165,8 @@ public:
            status_t        invoke(const Parcel& request, Parcel *reply);
            status_t        setMetadataFilter(const Parcel& filter);
            status_t        getMetadata(bool update_only, bool apply_filter, Parcel *metadata);
            status_t        suspend();
            status_t        resume();
private:
            void            clear_l();
            status_t        seekTo_l(int msec);
+47 −0
Original line number Diff line number Diff line
@@ -1063,6 +1063,53 @@ public class MediaPlayer

    private native void _reset();

    /**
     * Suspends the MediaPlayer. The only methods that may be called while
     * suspended are {@link #reset()}, {@link #release()} and {@link #resume()}.
     * MediaPlayer will release its hardware resources as far as
     * possible and reasonable. A successfully suspended MediaPlayer will
     * cease sending events.
     * If suspension is successful, this method returns true, otherwise
     * false is returned and the player's state is not affected.
     * @hide
     */
    public boolean suspend() {
        if (native_suspend_resume(true) < 0) {
            return false;
        }

        stayAwake(false);

        // make sure none of the listeners get called anymore
        mEventHandler.removeCallbacksAndMessages(null);

        return true;
    }

    /**
     * Resumes the MediaPlayer. Only to be called after a previous (successful)
     * call to {@link #suspend()}.
     * MediaPlayer will return to a state close to what it was in before
     * suspension.
     * @hide
     */
    public boolean resume() {
        if (native_suspend_resume(false) < 0) {
            return false;
        }

        if (isPlaying()) {
            stayAwake(true);
        }

        return true;
    }

    /**
     * @hide
     */
    private native int native_suspend_resume(boolean isSuspend);

    /**
     * Sets the audio stream type for this MediaPlayer. See {@link AudioManager}
     * for a list of stream types.
+14 −0
Original line number Diff line number Diff line
@@ -692,6 +692,19 @@ android_media_MediaPlayer_snoop(JNIEnv* env, jobject thiz, jobject data, jint ki
    return ret;
}

static jint
android_media_MediaPlayer_native_suspend_resume(
        JNIEnv *env, jobject thiz, jboolean isSuspend) {
    LOGV("suspend_resume(%d)", isSuspend);
    sp<MediaPlayer> mp = getMediaPlayer(env, thiz);
    if (mp == NULL ) {
        jniThrowException(env, "java/lang/IllegalStateException", NULL);
        return UNKNOWN_ERROR;
    }

    return isSuspend ? mp->suspend() : mp->resume();
}

// ----------------------------------------------------------------------------

static JNINativeMethod gMethods[] = {
@@ -724,6 +737,7 @@ static JNINativeMethod gMethods[] = {
    {"native_setup",        "(Ljava/lang/Object;)V",            (void *)android_media_MediaPlayer_native_setup},
    {"native_finalize",     "()V",                              (void *)android_media_MediaPlayer_native_finalize},
    {"snoop",               "([SI)I",                           (void *)android_media_MediaPlayer_snoop},
    {"native_suspend_resume", "(Z)I",                           (void *)android_media_MediaPlayer_native_suspend_resume},
};

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