explicitly release androids mediaplayer when component is unmounted (#319)

This commit is contained in:
nharlow89 2016-09-09 05:45:23 -07:00 committed by Matt Apperson
parent 83dd4c3ba9
commit 6dfbb1e2a5
2 changed files with 17 additions and 0 deletions

View File

@ -148,6 +148,17 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
} }
} }
public void cleanupMediaPlayerResources() {
if ( mediaController != null ) {
mediaController.hide();
}
if ( mMediaPlayer != null ) {
mMediaPlayerValid = false;
mMediaPlayer.stop();
mMediaPlayer.release();
}
}
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset) { public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset) {
mSrcUriString = uriString; mSrcUriString = uriString;

View File

@ -43,6 +43,12 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
return new ReactVideoView(themedReactContext); return new ReactVideoView(themedReactContext);
} }
@Override
public void onDropViewInstance(ReactVideoView view) {
super.onDropViewInstance(view);
view.cleanupMediaPlayerResources();
}
@Override @Override
@Nullable @Nullable
public Map getExportedCustomDirectEventTypeConstants() { public Map getExportedCustomDirectEventTypeConstants() {