Commit 0a12f738 authored by linguokun's avatar linguokun
Browse files

solve the memory leak on Android and avoid the crash on kikat when call mp.selectTrack(0);

parent 30c30ec5
Loading
Loading
Loading
Loading
+13 −0
Changes for android/src/main/java/com/brentvatne/react/ReactVideoView.java: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -232,12 +232,19 @@ public class ReactVideoView extends ScalableVideoView implements
            mediaController.hide();
        }
        if ( mMediaPlayer != null ) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                mMediaPlayer.setOnTimedMetaDataAvailableListener(null);
            }
            mMediaPlayerValid = false;
            release();
        }
        if (mIsFullscreen) {
            setFullscreen(false);
        }
        if (mThemedReactContext != null) {
            mThemedReactContext.removeLifecycleEventListener(this);
            mThemedReactContext = null;
        }
    }

    public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final ReadableMap requestHeaders) {
@@ -565,7 +572,10 @@ public class ReactVideoView extends ScalableVideoView implements
        }

        // Select track (so we can use it to listen to timed meta data updates)
        try{
            mp.selectTrack(0);
        }catch (Throwable t){
        }
    }

    @Override
@@ -601,7 +611,10 @@ public class ReactVideoView extends ScalableVideoView implements
    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        // Select track (so we can use it to listen to timed meta data updates)
        try{
            mp.selectTrack(0);
        }catch (Throwable t){
        }

        mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0);
    }