Commit 7e5647d5 authored by Gerardo Pacheco's avatar Gerardo Pacheco
Browse files

Android: MediaPlayer - Prevent screen from dimming, fixed bug and simplified code

parent 5435e5d5
Loading
Loading
Loading
Loading
+3 −15
Changes for android/src/main/java/com/brentvatne/react/ReactVideoView.java: 3 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -503,24 +503,12 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
        this.mUseNativeControls = controls;
    }

    public boolean isPreventScreenFromDimmingFlagOn() {
        int flags = mThemedReactContext.getCurrentActivity().getWindow().getAttributes().flags;

        if ((flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) {
            return false;
        }

        return true;
    }

    public void setPreventScreenFromDimmingFlag(final boolean state) {
        if (!mMediaPlayerValid && mThemedReactContext == null) {
        if (!mMediaPlayerValid || mThemedReactContext == null) {
            return;
        }

        final boolean isFlagOn = isPreventScreenFromDimmingFlagOn();

        if (state && !isFlagOn) {
        if (state) {
            mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
@@ -529,7 +517,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
            });
        }
        
        if (!state && isFlagOn) {
        if (!state) {
            mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {