feat: add full screen support based on expo-av implementation
This commit is contained in:
parent
7c48ae7c85
commit
b144a50f41
@ -0,0 +1,71 @@
|
|||||||
|
package com.brentvatne.exoplayer;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
import android.widget.ImageButton;
|
||||||
|
|
||||||
|
import com.google.android.exoplayer2.ui.PlayerControlView;
|
||||||
|
|
||||||
|
public class FullScreenPlayerView extends Dialog {
|
||||||
|
private final PlayerControlView playerControlView;
|
||||||
|
private final ExoPlayerView exoPlayerView;
|
||||||
|
private ViewGroup parent;
|
||||||
|
private final FrameLayout containerView;
|
||||||
|
|
||||||
|
public FullScreenPlayerView(Context context, ExoPlayerView exoPlayerView, PlayerControlView playerControlView) {
|
||||||
|
super(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
|
||||||
|
this.playerControlView = playerControlView;
|
||||||
|
this.exoPlayerView = exoPlayerView;
|
||||||
|
containerView = new FrameLayout(context);
|
||||||
|
setContentView(containerView, generateDefaultLayoutParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStart() {
|
||||||
|
parent = (FrameLayout)(exoPlayerView.getParent());
|
||||||
|
|
||||||
|
parent.removeView(exoPlayerView);
|
||||||
|
containerView.addView(exoPlayerView, generateDefaultLayoutParams());
|
||||||
|
|
||||||
|
if (playerControlView != null) {
|
||||||
|
ImageButton imageButton = playerControlView.findViewById(com.brentvatne.react.R.id.exo_fullscreen);
|
||||||
|
imageButton.setBackgroundResource(com.google.android.exoplayer2.ui.R.drawable.exo_icon_fullscreen_exit);
|
||||||
|
imageButton.setContentDescription(getContext().getString(com.google.android.exoplayer2.ui.R.string.exo_controls_fullscreen_exit_description));
|
||||||
|
parent.removeView(playerControlView);
|
||||||
|
containerView.addView(playerControlView, generateDefaultLayoutParams());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
containerView.removeView(exoPlayerView);
|
||||||
|
parent.addView(exoPlayerView, generateDefaultLayoutParams());
|
||||||
|
|
||||||
|
if (playerControlView != null) {
|
||||||
|
ImageButton imageButton = playerControlView.findViewById(com.brentvatne.react.R.id.exo_fullscreen);
|
||||||
|
imageButton.setBackgroundResource(com.google.android.exoplayer2.ui.R.drawable.exo_icon_fullscreen_enter);
|
||||||
|
imageButton.setContentDescription(getContext().getString(com.google.android.exoplayer2.ui.R.string.exo_controls_fullscreen_enter_description));
|
||||||
|
containerView.removeView(playerControlView);
|
||||||
|
parent.addView(playerControlView, generateDefaultLayoutParams());
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.requestLayout();
|
||||||
|
parent = null;
|
||||||
|
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private FrameLayout.LayoutParams generateDefaultLayoutParams() {
|
||||||
|
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
||||||
|
FrameLayout.LayoutParams.MATCH_PARENT
|
||||||
|
);
|
||||||
|
layoutParams.setMargins(0, 0, 0, 0);
|
||||||
|
return layoutParams;
|
||||||
|
}
|
||||||
|
}
|
@ -140,6 +140,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
private Player.Listener eventListener;
|
private Player.Listener eventListener;
|
||||||
|
|
||||||
private ExoPlayerView exoPlayerView;
|
private ExoPlayerView exoPlayerView;
|
||||||
|
private FullScreenPlayerView fullScreenPlayerView;
|
||||||
|
|
||||||
private DataSource.Factory mediaDataSourceFactory;
|
private DataSource.Factory mediaDataSourceFactory;
|
||||||
private ExoPlayer player;
|
private ExoPlayer player;
|
||||||
@ -399,6 +400,10 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Handling the fullScreenButton click event
|
||||||
|
ImageButton fullScreenButton = playerControlView.findViewById(R.id.exo_fullscreen);
|
||||||
|
fullScreenButton.setOnClickListener(v -> setFullscreen(!isFullscreen));
|
||||||
|
|
||||||
// Invoking onPlaybackStateChanged and onPlayWhenReadyChanged events for Player
|
// Invoking onPlaybackStateChanged and onPlayWhenReadyChanged events for Player
|
||||||
eventListener = new Player.Listener() {
|
eventListener = new Player.Listener() {
|
||||||
@Override
|
@Override
|
||||||
@ -664,6 +669,7 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
setControls(controls);
|
setControls(controls);
|
||||||
applyModifiers();
|
applyModifiers();
|
||||||
startBufferCheckTimer();
|
startBufferCheckTimer();
|
||||||
|
fullScreenPlayerView = new FullScreenPlayerView(getContext(), exoPlayerView, playerControlView);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {
|
private DrmSessionManager buildDrmSessionManager(UUID uuid, String licenseUrl, String[] keyRequestPropertiesArray) throws UnsupportedDrmException {
|
||||||
@ -1770,14 +1776,15 @@ class ReactExoplayerView extends FrameLayout implements
|
|||||||
| SYSTEM_UI_FLAG_FULLSCREEN;
|
| SYSTEM_UI_FLAG_FULLSCREEN;
|
||||||
}
|
}
|
||||||
eventEmitter.fullscreenWillPresent();
|
eventEmitter.fullscreenWillPresent();
|
||||||
decorView.setSystemUiVisibility(uiOptions);
|
fullScreenPlayerView.show();
|
||||||
eventEmitter.fullscreenDidPresent();
|
eventEmitter.fullscreenDidPresent();
|
||||||
} else {
|
} else {
|
||||||
uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
|
uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;
|
||||||
eventEmitter.fullscreenWillDismiss();
|
eventEmitter.fullscreenWillDismiss();
|
||||||
decorView.setSystemUiVisibility(uiOptions);
|
fullScreenPlayerView.dismiss();
|
||||||
eventEmitter.fullscreenDidDismiss();
|
eventEmitter.fullscreenDidDismiss();
|
||||||
}
|
}
|
||||||
|
post(() -> decorView.setSystemUiVisibility(uiOptions));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseTextureView(boolean useTextureView) {
|
public void setUseTextureView(boolean useTextureView) {
|
||||||
|
@ -71,6 +71,14 @@
|
|||||||
android:paddingRight="4dp"
|
android:paddingRight="4dp"
|
||||||
android:includeFontPadding="false"
|
android:includeFontPadding="false"
|
||||||
android:textColor="#FFBEBEBE"/>
|
android:textColor="#FFBEBEBE"/>
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@id/exo_fullscreen"
|
||||||
|
style="@style/ExoMediaButton.FullScreen"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_margin="4dp"
|
||||||
|
android:scaleType="fitCenter" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
7
android/src/main/res/values/styles.xml
Normal file
7
android/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<style name="ExoMediaButton.FullScreen">
|
||||||
|
<item name="android:src">@drawable/exo_icon_fullscreen_enter</item>
|
||||||
|
<item name="android:contentDescription">@string/exo_controls_fullscreen_enter_description</item>
|
||||||
|
</style>
|
||||||
|
</resources>
|
Loading…
Reference in New Issue
Block a user