From 6dfbb1e2a57863d249e78c68aa79fc1ca34e118d Mon Sep 17 00:00:00 2001 From: nharlow89 Date: Fri, 9 Sep 2016 05:45:23 -0700 Subject: [PATCH] explicitly release androids mediaplayer when component is unmounted (#319) --- .../java/com/brentvatne/react/ReactVideoView.java | 11 +++++++++++ .../com/brentvatne/react/ReactVideoViewManager.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index a3694409..5b002d4c 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -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) { mSrcUriString = uriString; diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java index 720240cd..7ab2bddf 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoViewManager.java @@ -43,6 +43,12 @@ public class ReactVideoViewManager extends SimpleViewManager { return new ReactVideoView(themedReactContext); } + @Override + public void onDropViewInstance(ReactVideoView view) { + super.onDropViewInstance(view); + view.cleanupMediaPlayerResources(); + } + @Override @Nullable public Map getExportedCustomDirectEventTypeConstants() {