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

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

Release the media player when trimming memory

Change-Id: I2bb2880546311761fc38d6208de080a66216fa2f
parent 4461f602
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
    static final int STATE_PREPARED           = 2;
    static final int STATE_PLAYING            = 3;
    static final int STATE_RESETTED           = 4;
    static final int STATE_RELEASED           = 5;

    protected HTML5VideoViewProxy mProxy;

@@ -126,7 +127,7 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
    }

    public void reset() {
        if (mCurrentState != STATE_RESETTED) {
        if (mCurrentState < STATE_RESETTED) {
            mPlayer.reset();
        }
        mCurrentState = STATE_RESETTED;
@@ -138,6 +139,18 @@ public class HTML5VideoView implements MediaPlayer.OnPreparedListener {
        }
    }

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

    public boolean isReleased() {
        return mCurrentState == STATE_RELEASED;
    }

    public boolean getPauseDuringPreparing() {
        return mPauseDuringPreparing;
    }
+5 −2
Original line number Diff line number Diff line
@@ -109,7 +109,8 @@ class HTML5VideoViewProxy extends Handler
            mBaseLayer = layer;
            // Don't do this for full screen mode.
            if (mHTML5VideoView != null
                && !mHTML5VideoView.isFullScreenMode()) {
                && !mHTML5VideoView.isFullScreenMode()
                && !mHTML5VideoView.isReleased()) {
                int currentVideoLayerId = mHTML5VideoView.getVideoLayerId();
                SurfaceTexture surfTexture =
                        HTML5VideoInline.getSurfaceTexture(currentVideoLayerId);
@@ -214,7 +215,9 @@ class HTML5VideoViewProxy extends Handler

            boolean skipPrepare = false;
            boolean createInlineView = false;
            if (backFromFullScreenMode && currentVideoLayerId == videoLayerId) {
            if (backFromFullScreenMode
                && currentVideoLayerId == videoLayerId
                && !mHTML5VideoView.isReleased()) {
                skipPrepare = true;
                createInlineView = true;
            } else if(backFromFullScreenMode
+1 −0
Original line number Diff line number Diff line
@@ -745,6 +745,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc
            // Here we just need to clean up the Surface Texture which is static.
            if (level > TRIM_MEMORY_UI_HIDDEN) {
                HTML5VideoInline.cleanupSurfaceTexture();
                HTML5VideoView.release();
            }
            WebViewClassic.nativeOnTrimMemory(level);
        }