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

Commit b1c2c1e3 authored by Teng-Hui Zhu's avatar Teng-Hui Zhu
Browse files

Release the media player when exiting the full screen

Once we switch out from full screen mode, the player will be re-created for the
next video, we should release the sources as early as possible.

bug:4332676
Change-Id: I4c26523b3600d3100f81e422979236fca57beb7c
parent 9c902c1a
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -107,6 +107,7 @@ public class HTML5VideoFullScreen extends HTML5VideoView
            // After we return from this we can't use the surface any more.
            // After we return from this we can't use the surface any more.
            // The current Video View will be destroy when we play a new video.
            // The current Video View will be destroy when we play a new video.
            pauseAndDispatch(mProxy);
            pauseAndDispatch(mProxy);
            mPlayer.release();
            mSurfaceHolder = null;
            mSurfaceHolder = null;
            if (mMediaController != null) {
            if (mMediaController != null) {
                mMediaController.hide();
                mMediaController.hide();
@@ -226,6 +227,10 @@ public class HTML5VideoFullScreen extends HTML5VideoView
                mProxy.getWebView().getViewManager().showAll();
                mProxy.getWebView().getViewManager().showAll();


                mProxy = null;
                mProxy = null;

                // Don't show the controller after exiting the full screen.
                mMediaController = null;
                mCurrentState = STATE_RELEASED;
            }
            }
        };
        };


+12 −4
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
    static final int STATE_NOTPREPARED        = 1;
    static final int STATE_NOTPREPARED        = 1;
    static final int STATE_PREPARED           = 2;
    static final int STATE_PREPARED           = 2;
    static final int STATE_PLAYING            = 3;
    static final int STATE_PLAYING            = 3;
    static final int STATE_RELEASED           = 4;
    protected int mCurrentState;
    protected int mCurrentState;


    protected HTML5VideoViewProxy mProxy;
    protected HTML5VideoViewProxy mProxy;
@@ -84,7 +85,7 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
    }
    }


    public void pause() {
    public void pause() {
        if (mCurrentState == STATE_PREPARED && mPlayer.isPlaying()) {
        if (isPlaying()) {
            mPlayer.pause();
            mPlayer.pause();
        } else if (mCurrentState == STATE_NOTPREPARED) {
        } else if (mCurrentState == STATE_NOTPREPARED) {
            mPauseDuringPreparing = true;
            mPauseDuringPreparing = true;
@@ -120,12 +121,19 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
    }
    }


    public boolean isPlaying() {
    public boolean isPlaying() {
        if (mCurrentState == STATE_PREPARED) {
            return mPlayer.isPlaying();
            return mPlayer.isPlaying();
        } else {
            return false;
        }
    }
    }


    public void release() {
    public void release() {
        if (mCurrentState != STATE_RELEASED) {
            mPlayer.release();
            mPlayer.release();
        }
        }
        mCurrentState = STATE_RELEASED;
    }


    public void stopPlayback() {
    public void stopPlayback() {
        if (mCurrentState == STATE_PREPARED) {
        if (mCurrentState == STATE_PREPARED) {
@@ -228,7 +236,7 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {




    public int getCurrentState() {
    public int getCurrentState() {
        if (mPlayer.isPlaying()) {
        if (isPlaying()) {
            return STATE_PLAYING;
            return STATE_PLAYING;
        } else {
        } else {
            return mCurrentState;
            return mCurrentState;