Switch to using setKeepScreenOn to prevent screen timeouts

This commit is contained in:
Hampton Maxwell 2018-08-05 17:27:49 -07:00 committed by GitHub
parent 99591e45d6
commit bd48a001c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -359,7 +359,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
} }
public void setPausedModifier(final boolean paused) { public void setPausedModifier(final boolean paused) {
mPaused = paused; mPaused = paused;
if (!mMediaPlayerValid) { if (!mMediaPlayerValid) {
@ -369,12 +368,10 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
if (mPaused) { if (mPaused) {
if (mMediaPlayer.isPlaying()) { if (mMediaPlayer.isPlaying()) {
pause(); pause();
setPreventScreenFromDimmingFlag(false);
} }
} else { } else {
if (!mMediaPlayer.isPlaying()) { if (!mMediaPlayer.isPlaying()) {
start(); start();
setPreventScreenFromDimmingFlag(true);
// Setting the rate unpauses, so we have to wait for an unpause // Setting the rate unpauses, so we have to wait for an unpause
if (mRate != mActiveRate) { if (mRate != mActiveRate) {
setRateModifier(mRate); setRateModifier(mRate);
@ -384,6 +381,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
mProgressUpdateHandler.post(mProgressUpdateRunnable); mProgressUpdateHandler.post(mProgressUpdateRunnable);
} }
} }
setKeepScreenOn(!mPaused);
} }
// reduces the volume based on stereoPan // reduces the volume based on stereoPan
@ -503,36 +501,6 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
this.mUseNativeControls = controls; 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 @Override
public void onPrepared(MediaPlayer mp) { public void onPrepared(MediaPlayer mp) {
@ -663,27 +631,22 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
@Override @Override
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
mMediaPlayerValid = false; mMediaPlayerValid = false;
super.onDetachedFromWindow(); super.onDetachedFromWindow();
setKeepScreenOn(false);
setPreventScreenFromDimmingFlag(false);
} }
@Override @Override
protected void onAttachedToWindow() { protected void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
setPreventScreenFromDimmingFlag(true);
if(mMainVer>0) { if(mMainVer>0) {
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer); setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders, mMainVer, mPatchVer);
} }
else { else {
setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders); setSrc(mSrcUriString, mSrcType, mSrcIsNetwork, mSrcIsAsset, mRequestHeaders);
} }
setKeepScreenOn(true);
} }
@Override @Override