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

Commit 002ecd21 authored by Roger Chen's avatar Roger Chen Committed by Gerrit Code Review
Browse files

Audio continue to played even if paused manually



Currently, audio will resume playing after a phone call
or notification even if the user had manually paused playback.

This patch addresses that by introducing a new player state
to distinguish the user pausing playback and the browser
losing audio focus for some other reason. Audio will only
 resume if the browser temporarily lost audio focus and
not when the user has manually paused playback.

Change-Id: I9e8beaedb0fcc5afe920068297ed9c387eab2ac8
Signed-off-by: default avatarRoger Chen <cxr514033970@gmail.com>
parent b6a2978a
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ class HTML5Audio extends Handler
    private static int STARTED             =  4;
    private static int COMPLETE            =  5;
    private static int PAUSED              =  6;
    private static int PAUSED_TRANSITORILY =  7;
    private static int STOPPED             = -2;
    private static int ERROR               = -1;

@@ -247,7 +248,7 @@ class HTML5Audio extends Handler
            // resume playback
            if (mMediaPlayer == null) {
                resetMediaPlayer();
            } else if (mState != ERROR && !mMediaPlayer.isPlaying()) {
            } else if (mState == PAUSED_TRANSITORILY && !mMediaPlayer.isPlaying()) {
                mMediaPlayer.start();
                mState = STARTED;
            }
@@ -265,7 +266,9 @@ class HTML5Audio extends Handler
        case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
            // Lost focus for a short time, but we have to stop
            // playback.
            if (mState != ERROR && mMediaPlayer.isPlaying()) pause();
            if (mState != ERROR && mMediaPlayer.isPlaying()) {
                pause(PAUSED_TRANSITORILY);
            }
            break;
        }
    }
@@ -298,12 +301,16 @@ class HTML5Audio extends Handler
    }

    private void pause() {
        pause(PAUSED);
    }

    private void pause(int state) {
        if (mState == STARTED) {
            if (mTimer != null) {
                mTimer.purge();
            }
            mMediaPlayer.pause();
            mState = PAUSED;
            mState = state;
        }
    }