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

This commit is contained in:
linguokun 2018-11-15 17:57:37 +08:00
parent 30c30ec575
commit 0a12f7389e

View File

@ -232,12 +232,19 @@ public class ReactVideoView extends ScalableVideoView implements
mediaController.hide(); mediaController.hide();
} }
if ( mMediaPlayer != null ) { if ( mMediaPlayer != null ) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
mMediaPlayer.setOnTimedMetaDataAvailableListener(null);
}
mMediaPlayerValid = false; mMediaPlayerValid = false;
release(); release();
} }
if (mIsFullscreen) { if (mIsFullscreen) {
setFullscreen(false); 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) { 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) // Select track (so we can use it to listen to timed meta data updates)
try{
mp.selectTrack(0); mp.selectTrack(0);
}catch (Throwable t){
}
} }
@Override @Override
@ -601,7 +611,10 @@ public class ReactVideoView extends ScalableVideoView implements
@Override @Override
public void onBufferingUpdate(MediaPlayer mp, int percent) { public void onBufferingUpdate(MediaPlayer mp, int percent) {
// Select track (so we can use it to listen to timed meta data updates) // Select track (so we can use it to listen to timed meta data updates)
try{
mp.selectTrack(0); mp.selectTrack(0);
}catch (Throwable t){
}
mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0); mVideoBufferedDuration = (int) Math.round((double) (mVideoDuration * percent) / 100.0);
} }