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) {
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