diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index 44e7a9ee..2342413b 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -1,6 +1,7 @@ package com.brentvatne.exoplayer; import android.annotation.SuppressLint; +import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.net.Uri; @@ -8,6 +9,8 @@ import android.os.Handler; import android.os.Message; import android.text.TextUtils; import android.util.Log; +import android.view.View; +import android.view.Window; import android.widget.FrameLayout; import com.brentvatne.react.R; @@ -85,6 +88,7 @@ class ReactExoplayerView extends FrameLayout implements private int resumeWindow; private long resumePosition; private boolean loadVideoStarted; + private boolean isFullscreen; private boolean isPaused = true; private boolean isBuffering; private float rate = 1f; @@ -331,6 +335,9 @@ class ReactExoplayerView extends FrameLayout implements } private void onStopPlayback() { + if (isFullscreen) { + setFullscreen(false); + } setKeepScreenOn(false); audioManager.abandonAudioFocus(this); } @@ -638,4 +645,37 @@ class ReactExoplayerView extends FrameLayout implements public void setDisableFocus(boolean disableFocus) { this.disableFocus = disableFocus; } + + public void setFullscreen(boolean fullscreen) { + if (fullscreen == isFullscreen) { + return; // Avoid generating events when nothing is changing + } + isFullscreen = fullscreen; + + Activity activity = themedReactContext.getCurrentActivity(); + if (activity == null) { + return; + } + Window window = activity.getWindow(); + View decorView = window.getDecorView(); + int uiOptions; + if (isFullscreen) { + if (Util.SDK_INT >= 19) { // 4.4+ + uiOptions = SYSTEM_UI_FLAG_HIDE_NAVIGATION + | SYSTEM_UI_FLAG_IMMERSIVE_STICKY + | SYSTEM_UI_FLAG_FULLSCREEN; + } else { + uiOptions = SYSTEM_UI_FLAG_HIDE_NAVIGATION + | SYSTEM_UI_FLAG_FULLSCREEN; + } + eventEmitter.fullscreenWillPresent(); + decorView.setSystemUiVisibility(uiOptions); + eventEmitter.fullscreenDidPresent(); + } else { + uiOptions = View.SYSTEM_UI_FLAG_VISIBLE; + eventEmitter.fullscreenWillDismiss(); + decorView.setSystemUiVisibility(uiOptions); + eventEmitter.fullscreenDidDismiss(); + } + } } diff --git a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java index ff3b4555..ab2eda86 100644 --- a/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java +++ b/android-exoplayer/src/main/java/com/brentvatne/exoplayer/VideoEventEmitter.java @@ -31,6 +31,11 @@ class VideoEventEmitter { private static final String EVENT_PROGRESS = "onVideoProgress"; private static final String EVENT_SEEK = "onVideoSeek"; private static final String EVENT_END = "onVideoEnd"; + private static final String EVENT_FULLSCREEN_WILL_PRESENT = "onVideoFullscreenPlayerWillPresent"; + private static final String EVENT_FULLSCREEN_DID_PRESENT = "onVideoFullscreenPlayerDidPresent"; + private static final String EVENT_FULLSCREEN_WILL_DISMISS = "onVideoFullscreenPlayerWillDismiss"; + private static final String EVENT_FULLSCREEN_DID_DISMISS = "onVideoFullscreenPlayerDidDismiss"; + private static final String EVENT_STALLED = "onPlaybackStalled"; private static final String EVENT_RESUME = "onPlaybackResume"; private static final String EVENT_READY = "onReadyForDisplay"; @@ -48,6 +53,10 @@ class VideoEventEmitter { EVENT_PROGRESS, EVENT_SEEK, EVENT_END, + EVENT_FULLSCREEN_WILL_PRESENT, + EVENT_FULLSCREEN_DID_PRESENT, + EVENT_FULLSCREEN_WILL_DISMISS, + EVENT_FULLSCREEN_DID_DISMISS, EVENT_STALLED, EVENT_RESUME, EVENT_READY, @@ -67,6 +76,10 @@ class VideoEventEmitter { EVENT_PROGRESS, EVENT_SEEK, EVENT_END, + EVENT_FULLSCREEN_WILL_PRESENT, + EVENT_FULLSCREEN_DID_PRESENT, + EVENT_FULLSCREEN_WILL_DISMISS, + EVENT_FULLSCREEN_DID_DISMISS, EVENT_STALLED, EVENT_RESUME, EVENT_READY, @@ -175,6 +188,22 @@ class VideoEventEmitter { receiveEvent(EVENT_END, null); } + void fullscreenWillPresent() { + receiveEvent(EVENT_FULLSCREEN_WILL_PRESENT, null); + } + + void fullscreenDidPresent() { + receiveEvent(EVENT_FULLSCREEN_DID_PRESENT, null); + } + + void fullscreenWillDismiss() { + receiveEvent(EVENT_FULLSCREEN_WILL_DISMISS, null); + } + + void fullscreenDidDismiss() { + receiveEvent(EVENT_FULLSCREEN_DID_DISMISS, null); + } + void error(String errorString, Exception exception) { WritableMap error = Arguments.createMap(); error.putString(EVENT_PROP_ERROR_STRING, errorString);