Implement hacky fullscreen

This only handles the controls portion of fullscreen. It doesn't make the video use the entire screen, that still needs to be done via styles. Will be implemented later
This commit is contained in:
Hampton Maxwell 2018-07-17 17:47:19 -07:00
parent aa4e1812e9
commit 18efffbd1a
2 changed files with 51 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package com.brentvatne.react; package com.brentvatne.react;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.AssetFileDescriptor; import android.content.res.AssetFileDescriptor;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.media.MediaPlayer; import android.media.MediaPlayer;
@ -9,6 +10,8 @@ import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.widget.MediaController; import android.widget.MediaController;
@ -46,7 +49,11 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
EVENT_END("onVideoEnd"), EVENT_END("onVideoEnd"),
EVENT_STALLED("onPlaybackStalled"), EVENT_STALLED("onPlaybackStalled"),
EVENT_RESUME("onPlaybackResume"), EVENT_RESUME("onPlaybackResume"),
EVENT_READY_FOR_DISPLAY("onReadyForDisplay"); EVENT_READY_FOR_DISPLAY("onReadyForDisplay"),
EVENT_FULLSCREEN_WILL_PRESENT("onVideoFullscreenPlayerWillPresent"),
EVENT_FULLSCREEN_DID_PRESENT("onVideoFullscreenPlayerDidPresent"),
EVENT_FULLSCREEN_WILL_DISMISS("onVideoFullscreenPlayerWillDismiss"),
EVENT_FULLSCREEN_DID_DISMISS("onVideoFullscreenPlayerDidDismiss");
private final String mName; private final String mName;
@ -106,6 +113,7 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
private float mActiveRate = 1.0f; private float mActiveRate = 1.0f;
private boolean mPlayInBackground = false; private boolean mPlayInBackground = false;
private boolean mBackgroundPaused = false; private boolean mBackgroundPaused = false;
private boolean mIsFullscreen = false;
private int mMainVer = 0; private int mMainVer = 0;
private int mPatchVer = 0; private int mPatchVer = 0;
@ -208,6 +216,9 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
mMediaPlayerValid = false; mMediaPlayerValid = false;
release(); release();
} }
if (mIsFullscreen) {
setFullscreen(false);
}
} }
public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final ReadableMap requestHeaders) { public void setSrc(final String uriString, final String type, final boolean isNetwork, final boolean isAsset, final ReadableMap requestHeaders) {
@ -439,6 +450,39 @@ public class ReactVideoView extends ScalableVideoView implements MediaPlayer.OnP
} }
} }
public void setFullscreen(boolean isFullscreen) {
if (isFullscreen == mIsFullscreen) {
return; // Avoid generating events when nothing is changing
}
mIsFullscreen = isFullscreen;
Activity activity = mThemedReactContext.getCurrentActivity();
if (activity == null) {
return;
}
Window window = activity.getWindow();
View decorView = window.getDecorView();
int uiOptions;
if (mIsFullscreen) {
if (Build.VERSION.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;
}
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_WILL_PRESENT.toString(), null);
decorView.setSystemUiVisibility(uiOptions);
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_DID_PRESENT.toString(), null);
} else {
uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_WILL_DISMISS.toString(), null);
decorView.setSystemUiVisibility(uiOptions);
mEventEmitter.receiveEvent(getId(), Events.EVENT_FULLSCREEN_DID_DISMISS.toString(), null);
}
}
public void applyModifiers() { public void applyModifiers() {
setResizeModeModifier(mResizeMode); setResizeModeModifier(mResizeMode);
setRepeatModifier(mRepeat); setRepeatModifier(mRepeat);

View File

@ -35,6 +35,7 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
public static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval"; public static final String PROP_PROGRESS_UPDATE_INTERVAL = "progressUpdateInterval";
public static final String PROP_SEEK = "seek"; public static final String PROP_SEEK = "seek";
public static final String PROP_RATE = "rate"; public static final String PROP_RATE = "rate";
public static final String PROP_FULLSCREEN = "fullscreen";
public static final String PROP_PLAY_IN_BACKGROUND = "playInBackground"; public static final String PROP_PLAY_IN_BACKGROUND = "playInBackground";
public static final String PROP_CONTROLS = "controls"; public static final String PROP_CONTROLS = "controls";
@ -148,6 +149,11 @@ public class ReactVideoViewManager extends SimpleViewManager<ReactVideoView> {
videoView.setRateModifier(rate); videoView.setRateModifier(rate);
} }
@ReactProp(name = PROP_FULLSCREEN, defaultBoolean = false)
public void setFullscreen(final ReactVideoView videoView, final boolean fullscreen) {
videoView.setFullscreen(fullscreen);
}
@ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false) @ReactProp(name = PROP_PLAY_IN_BACKGROUND, defaultBoolean = false)
public void setPlayInBackground(final ReactVideoView videoView, final boolean playInBackground) { public void setPlayInBackground(final ReactVideoView videoView, final boolean playInBackground) {
videoView.setPlayInBackground(playInBackground); videoView.setPlayInBackground(playInBackground);