Skip to content

Commit

Permalink
Controller progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
moneytoo committed Jul 25, 2024
1 parent bdc4aa5 commit 764aacc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,10 @@ public void show() {
controlViewLayoutManager.show();
}

public void showProgress() {
controlViewLayoutManager.showProgress();
}

/** Hides the controller. */
public void hide() {
controlViewLayoutManager.hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
private boolean needToShowBars;
private boolean animationEnabled;

float translationYForProgressBar;

@SuppressWarnings({"nullness:method.invocation", "nullness:methodref.receiver.bound"})
public PlayerControlViewLayoutManager(PlayerControlView playerControlView) {
this.playerControlView = playerControlView;
Expand Down Expand Up @@ -194,7 +196,7 @@ public void onAnimationStart(Animator animation) {
});

Resources resources = playerControlView.getResources();
float translationYForProgressBar =
translationYForProgressBar =
resources.getDimension(R.dimen.exo_styled_bottom_bar_height)
- resources.getDimension(R.dimen.exo_styled_progress_bar_height);
float translationYForNoBars = resources.getDimension(R.dimen.exo_styled_bottom_bar_height);
Expand Down Expand Up @@ -461,6 +463,16 @@ private void setUxState(int uxState) {
}
}

private void setUxStateSilently(int uxState) {
int prevUxState = this.uxState;
this.uxState = uxState;
if (uxState == UX_STATE_NONE_VISIBLE) {
playerControlView.setVisibility(View.GONE);
} else if (prevUxState == UX_STATE_NONE_VISIBLE) {
playerControlView.setVisibility(View.VISIBLE);
}
}

public void onLayout(boolean changed, int left, int top, int right, int bottom) {
if (controlsBackground != null) {
// The background view should occupy the entirety of the parent. This is done in code rather
Expand Down Expand Up @@ -526,6 +538,29 @@ private void showAllBars() {
resetHideCallbacks();
}

public void showProgress() {
switch (uxState) {
case UX_STATE_ALL_VISIBLE:
hideMainBarAnimator.start();
break;
case UX_STATE_NONE_VISIBLE:
setUxStateSilently(UX_STATE_ONLY_PROGRESS_VISIBLE);

if (timeBar instanceof DefaultTimeBar) {
DefaultTimeBar defaultTimeBar = (DefaultTimeBar) timeBar;
defaultTimeBar.hideScrubber(false);
}

timeBar.setTranslationY(translationYForProgressBar);
bottomBar.setTranslationY(translationYForProgressBar);
break;
}
}

public boolean isProgress() {
return uxState == UX_STATE_ONLY_PROGRESS_VISIBLE;
}

private void hideAllBars() {
hideAllBarsAnimator.start();
}
Expand Down
12 changes: 12 additions & 0 deletions libraries/ui/src/main/java/androidx/media3/ui/PlayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,18 @@ public void hideController() {
}
}

public void hideControllerImmediately() {
if (controller != null) {
controller.hideImmediately();
}
}

public void showProgress() {
if (controller != null) {
controller.showProgress();
}
}

/**
* Returns the playback controls timeout. The playback controls are automatically hidden after
* this duration of time has elapsed without user input and with playback or buffering in
Expand Down

0 comments on commit 764aacc

Please sign in to comment.