From ab273ed1b5bc75610f8907b6ce63a14eaa722dd7 Mon Sep 17 00:00:00 2001 From: Gerardo Pacheco Date: Wed, 25 Jul 2018 10:24:48 +0200 Subject: [PATCH] Android: MediaPlayer - Prevent screen from dimming, check for activity --- .../java/com/brentvatne/react/ReactVideoView.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/brentvatne/react/ReactVideoView.java b/android/src/main/java/com/brentvatne/react/ReactVideoView.java index a8cd590c..c3b52f02 100644 --- a/android/src/main/java/com/brentvatne/react/ReactVideoView.java +++ b/android/src/main/java/com/brentvatne/react/ReactVideoView.java @@ -508,20 +508,25 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP return; } + Activity activity = mThemedReactContext.getCurrentActivity(); + if (activity == null) { + return; + } + if (state) { - mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - mThemedReactContext.getCurrentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }); } if (!state) { - mThemedReactContext.getCurrentActivity().runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - mThemedReactContext.getCurrentActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + activity.getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); } }); }