feat(android): add live video label configuration (#4190)
This commit is contained in:
committed by
GitHub
parent
82dc4cf3a0
commit
149924ffcb
@@ -10,6 +10,7 @@ import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import android.widget.FrameLayout
|
||||
import android.widget.ImageButton
|
||||
import android.widget.LinearLayout
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
@@ -216,5 +217,13 @@ class FullScreenPlayerView(
|
||||
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
)
|
||||
}
|
||||
if (controlsConfig.hideNotificationBarOnFullScreenMode) {
|
||||
val liveContainer = playerControlView?.findViewById<LinearLayout?>(com.brentvatne.react.R.id.exo_live_container)
|
||||
liveContainer?.let {
|
||||
val layoutParams = it.layoutParams as LinearLayout.LayoutParams
|
||||
layoutParams.topMargin = 40
|
||||
it.layoutParams = layoutParams
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -527,88 +527,78 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
view.layout(view.getLeft(), view.getTop(), view.getMeasuredWidth(), view.getMeasuredHeight());
|
||||
}
|
||||
|
||||
private void refreshControlsStyles (){
|
||||
if(playerControlView == null) return;
|
||||
private void refreshControlsStyles() {
|
||||
if (playerControlView == null || player == null || !controls) return;
|
||||
updateLiveContent();
|
||||
updatePlayPauseButtons();
|
||||
updateButtonVisibility(controlsConfig.getHideForward(), R.id.exo_ffwd);
|
||||
updateButtonVisibility(controlsConfig.getHideRewind(), R.id.exo_rew);
|
||||
updateButtonVisibility(controlsConfig.getHideNext(), R.id.exo_next);
|
||||
updateButtonVisibility(controlsConfig.getHidePrevious(), R.id.exo_prev);
|
||||
updateViewVisibility(playerControlView.findViewById(R.id.exo_fullscreen), controlsConfig.getHideFullscreen(), GONE);
|
||||
updateViewVisibility(playerControlView.findViewById(R.id.exo_position), controlsConfig.getHidePosition(), GONE);
|
||||
updateViewVisibility(playerControlView.findViewById(R.id.exo_progress), controlsConfig.getHideSeekBar(), INVISIBLE);
|
||||
updateViewVisibility(playerControlView.findViewById(R.id.exo_duration), controlsConfig.getHideDuration(), GONE);
|
||||
}
|
||||
|
||||
private void updateLiveContent() {
|
||||
LinearLayout exoLiveContainer = playerControlView.findViewById(R.id.exo_live_container);
|
||||
TextView exoLiveLabel = playerControlView.findViewById(R.id.exo_live_label);
|
||||
|
||||
boolean isLive = false;
|
||||
Timeline timeline = player.getCurrentTimeline();
|
||||
|
||||
// Determine if the content is live
|
||||
if (!timeline.isEmpty()) {
|
||||
Timeline.Window window = new Timeline.Window();
|
||||
timeline.getWindow(player.getCurrentMediaItemIndex(), window);
|
||||
isLive = window.isLive();
|
||||
}
|
||||
|
||||
if (isLive && controlsConfig.getLiveLabel() != null) {
|
||||
exoLiveLabel.setText(controlsConfig.getLiveLabel());
|
||||
exoLiveContainer.setVisibility(VISIBLE);
|
||||
} else {
|
||||
exoLiveContainer.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePlayPauseButtons() {
|
||||
final ImageButton playButton = playerControlView.findViewById(R.id.exo_play);
|
||||
final ImageButton pauseButton = playerControlView.findViewById(R.id.exo_pause);
|
||||
|
||||
if (controlsConfig.getHidePlayPause()) {
|
||||
playPauseControlContainer.setAlpha(0);
|
||||
|
||||
playButton.setClickable(false);
|
||||
pauseButton.setClickable(false);
|
||||
} else {
|
||||
playPauseControlContainer.setAlpha(1.0f);
|
||||
|
||||
playButton.setClickable(true);
|
||||
pauseButton.setClickable(true);
|
||||
}
|
||||
}
|
||||
|
||||
final ImageButton forwardButton = playerControlView.findViewById(R.id.exo_ffwd);
|
||||
if (controlsConfig.getHideForward()) {
|
||||
forwardButton.setImageAlpha(0);
|
||||
forwardButton.setClickable(false);
|
||||
private void updateButtonVisibility(boolean hide, int buttonID) {
|
||||
ImageButton button = playerControlView.findViewById(buttonID);
|
||||
if (hide) {
|
||||
button.setImageAlpha(0);
|
||||
button.setClickable(false);
|
||||
} else {
|
||||
forwardButton.setImageAlpha(255);
|
||||
forwardButton.setClickable(true);
|
||||
}
|
||||
|
||||
final ImageButton rewindButton = playerControlView.findViewById(R.id.exo_rew);
|
||||
if (controlsConfig.getHideRewind()) {
|
||||
rewindButton.setImageAlpha(0);
|
||||
rewindButton.setClickable(false);
|
||||
} else {
|
||||
rewindButton.setImageAlpha(255);
|
||||
rewindButton.setClickable(true);
|
||||
}
|
||||
|
||||
final ImageButton nextButton = playerControlView.findViewById(R.id.exo_next);
|
||||
if (controlsConfig.getHideNext()) {
|
||||
nextButton.setClickable(false);
|
||||
nextButton.setImageAlpha(0);
|
||||
} else {
|
||||
nextButton.setImageAlpha(255);
|
||||
nextButton.setClickable(true);
|
||||
}
|
||||
|
||||
final ImageButton previousButton = playerControlView.findViewById(R.id.exo_prev);
|
||||
if (controlsConfig.getHidePrevious()) {
|
||||
previousButton.setImageAlpha(0);
|
||||
previousButton.setClickable(false);
|
||||
} else {
|
||||
previousButton.setImageAlpha(255);
|
||||
previousButton.setClickable(true);
|
||||
}
|
||||
|
||||
final ImageButton fullscreenButton = playerControlView.findViewById(R.id.exo_fullscreen);
|
||||
if (controlsConfig.getHideFullscreen()) {
|
||||
fullscreenButton.setVisibility(GONE);
|
||||
} else if (fullscreenButton.getVisibility() == GONE) {
|
||||
fullscreenButton.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
final TextView positionText = playerControlView.findViewById(R.id.exo_position);
|
||||
if(controlsConfig.getHidePosition()){
|
||||
positionText.setVisibility(GONE);
|
||||
} else if (positionText.getVisibility() == GONE){
|
||||
positionText.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
final DefaultTimeBar progressBar = playerControlView.findViewById(R.id.exo_progress);
|
||||
if (controlsConfig.getHideSeekBar()) {
|
||||
progressBar.setVisibility(INVISIBLE);
|
||||
} else if (progressBar.getVisibility() == INVISIBLE) {
|
||||
progressBar.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
final TextView durationText = playerControlView.findViewById(R.id.exo_duration);
|
||||
if (controlsConfig.getHideDuration()) {
|
||||
durationText.setVisibility(GONE);
|
||||
} else if (durationText.getVisibility() == GONE) {
|
||||
durationText.setVisibility(VISIBLE);
|
||||
button.setImageAlpha(255);
|
||||
button.setClickable(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateViewVisibility(View view, boolean hide, int hideVisibility) {
|
||||
if (hide) {
|
||||
view.setVisibility(hideVisibility);
|
||||
} else if (view.getVisibility() == hideVisibility) {
|
||||
view.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void reLayoutControls() {
|
||||
reLayout(exoPlayerView);
|
||||
reLayout(playerControlView);
|
||||
@@ -1508,6 +1498,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
eventEmitter.onVideoLoad.invoke(duration, currentPosition, width, height,
|
||||
audioTracks, textTracks, videoTracks, trackId);
|
||||
refreshControlsStyles();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1757,7 +1748,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
eventEmitter.onVideoPlaybackStateChanged.invoke(isPlaying, isSeeking);
|
||||
|
||||
|
||||
if (isPlaying) {
|
||||
isSeeking = false;
|
||||
}
|
||||
@@ -2406,6 +2397,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
removeViewAt(indexOfPC);
|
||||
}
|
||||
}
|
||||
refreshControlsStyles();
|
||||
}
|
||||
|
||||
public void setSubtitleStyle(SubtitleStyle style) {
|
||||
@@ -2440,4 +2432,4 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
controlsConfig = controlsStyles;
|
||||
refreshControlsStyles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user