diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index dddd1507..b4348114 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -359,7 +359,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP } public void setPausedModifier(final boolean paused) { - mPaused = paused; if (!mMediaPlayerValid) { @@ -369,12 +368,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP if (mPaused) { if (mMediaPlayer.isPlaying()) { pause(); - setPreventScreenFromDimmingFlag(false); } } else { if (!mMediaPlayer.isPlaying()) { start(); - setPreventScreenFromDimmingFlag(true); // Setting the rate unpauses, so we have to wait for an unpause if (mRate != mActiveRate) { setRateModifier(mRate); @@ -384,6 +381,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP mProgressUpdateHandler.post(mProgressUpdateRunnable); } } + setKeepScreenOn(!mPaused); } // reduces the volume based on stereoPan @@ -503,36 +501,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP this.mUseNativeControls = controls; } - public void setPreventScreenFromDimmingFlag(final boolean state) { - if (!mMediaPlayerValid || mThemedReactContext == null) { - return; - } - - final Activity activity = mThemedReactContext.getCurrentActivity(); - if (activity == null) { - return; - } - - if (state) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - }); - } - - if (!state) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - activity.getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - } - }); - } - } - - @Override public void onPrepared(MediaPlayer mp) { @@ -663,27 +631,22 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP @Override protected void onDetachedFromWindow() { - mMediaPlayerValid = false; super.onDetachedFromWindow(); - - setPreventScreenFromDimmingFlag(false); + setKeepScreenOn(false); } @Override protected void onAttachedToWindow() { - super.onAttachedToWindow(); - setPreventScreenFromDimmingFlag(true); - if(mMainVer>0) { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer); } else { setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders); } - + setKeepScreenOn(true); } @Override