mirror of
https://github.com/samsonjs/media.git
synced 2026-04-09 11:55:46 +00:00
UI parameter to disable automatically showing playback controls.
(Fixing GitHub issue #2699) Added controllerAutoShow parameter to decide whether playback controls are shown automatically. Default is true. Can be overwritten in the XML with auto_show=false or via SimpleExoPlayerView.setControllerAutoShow(false). Also inverted the logic of maybeShowControllers and showController. SimpleExoPlayerView.(show/hide)Controller and PlaybackControlView.(show/hide) now unconditionally do what they say to allow manual operation. SimpleExoPlayerView.maybeShowController is used internally to automatically show playback controls. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=158712277
This commit is contained in:
parent
dcc2f9bd67
commit
fa4f876668
4 changed files with 74 additions and 20 deletions
|
|
@ -205,8 +205,6 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
// Show the controls on any key event.
|
||||
simpleExoPlayerView.showController();
|
||||
// If the event was not handled then see if the player view can handle it as a media key event.
|
||||
return super.dispatchKeyEvent(event) || simpleExoPlayerView.dispatchMediaKeyEvent(event);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -959,11 +959,7 @@ public class PlaybackControlView extends FrameLayout {
|
|||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
boolean handled = dispatchMediaKeyEvent(event) || super.dispatchKeyEvent(event);
|
||||
if (handled) {
|
||||
show();
|
||||
}
|
||||
return handled;
|
||||
return dispatchMediaKeyEvent(event) || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1005,7 +1001,6 @@ public class PlaybackControlView extends FrameLayout {
|
|||
break;
|
||||
}
|
||||
}
|
||||
show();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,6 +88,14 @@ import java.util.List;
|
|||
* <li>Default: {@code true}</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li><b>{@code auto_show}</b> - Whether the playback controls are automatically shown when
|
||||
* playback starts, pauses, ends, or fails. If set to false, the playback controls can be
|
||||
* manually operated with {@link #showController()} and {@link #hideController()}.
|
||||
* <ul>
|
||||
* <li>Corresponding method: {@link #setControllerAutoShow(boolean)}</li>
|
||||
* <li>Default: {@code true}</li>
|
||||
* </ul>
|
||||
* </li>
|
||||
* <li><b>{@code resize_mode}</b> - Controls how video and album art is resized within the view.
|
||||
* Valid values are {@code fit}, {@code fixed_width}, {@code fixed_height} and {@code fill}.
|
||||
* <ul>
|
||||
|
|
@ -198,6 +206,7 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
private boolean useArtwork;
|
||||
private Bitmap defaultArtwork;
|
||||
private int controllerShowTimeoutMs;
|
||||
private boolean controllerAutoShow;
|
||||
private boolean controllerHideOnTouch;
|
||||
|
||||
public SimpleExoPlayerView(Context context) {
|
||||
|
|
@ -238,6 +247,7 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
int resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT;
|
||||
int controllerShowTimeoutMs = PlaybackControlView.DEFAULT_SHOW_TIMEOUT_MS;
|
||||
boolean controllerHideOnTouch = true;
|
||||
boolean controllerAutoShow = true;
|
||||
if (attrs != null) {
|
||||
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
|
||||
R.styleable.SimpleExoPlayerView, 0, 0);
|
||||
|
|
@ -254,6 +264,8 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
controllerShowTimeoutMs);
|
||||
controllerHideOnTouch = a.getBoolean(R.styleable.SimpleExoPlayerView_hide_on_touch,
|
||||
controllerHideOnTouch);
|
||||
controllerAutoShow = a.getBoolean(R.styleable.SimpleExoPlayerView_auto_show,
|
||||
controllerAutoShow);
|
||||
} finally {
|
||||
a.recycle();
|
||||
}
|
||||
|
|
@ -317,6 +329,7 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
}
|
||||
this.controllerShowTimeoutMs = controller != null ? controllerShowTimeoutMs : 0;
|
||||
this.controllerHideOnTouch = controllerHideOnTouch;
|
||||
this.controllerAutoShow = controllerAutoShow;
|
||||
this.useController = useController && controller != null;
|
||||
hideController();
|
||||
}
|
||||
|
|
@ -480,6 +493,11 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean dispatchKeyEvent(KeyEvent event) {
|
||||
return dispatchMediaKeyEvent(event) || super.dispatchKeyEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called to process media key events. Any {@link KeyEvent} can be passed but only media key
|
||||
* events will be handled. Does nothing if playback controls are disabled.
|
||||
|
|
@ -488,16 +506,22 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
* @return Whether the key event was handled.
|
||||
*/
|
||||
public boolean dispatchMediaKeyEvent(KeyEvent event) {
|
||||
return useController && controller.dispatchMediaKeyEvent(event);
|
||||
boolean handled = useController && controller.dispatchMediaKeyEvent(event);
|
||||
if (handled) {
|
||||
maybeShowController(true);
|
||||
}
|
||||
return handled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the playback controls. Does nothing if playback controls are disabled.
|
||||
*
|
||||
* <p>The playback controls are automatically hidden during playback after
|
||||
* {{@link #getControllerShowTimeoutMs()}}. They are shown indefinitely when playback has not
|
||||
* started yet, is paused, has ended or failed.
|
||||
*/
|
||||
public void showController() {
|
||||
if (useController) {
|
||||
maybeShowController(true);
|
||||
}
|
||||
showController(shouldShowControllerIndefinitely());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -550,6 +574,26 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
this.controllerHideOnTouch = controllerHideOnTouch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the playback controls are automatically shown when playback starts, pauses,
|
||||
* ends, or fails. If set to false, the playback controls can be manually operated with {@link
|
||||
* #showController()} and {@link #hideController()}.
|
||||
*/
|
||||
public boolean getControllerAutoShow() {
|
||||
return controllerAutoShow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the playback controls are automatically shown when playback starts, pauses, ends,
|
||||
* or fails. If set to false, the playback controls can be manually operated with {@link
|
||||
* #showController()} and {@link #hideController()}.
|
||||
*
|
||||
* @param controllerAutoShow Whether the playback controls are allowed to show automatically.
|
||||
*/
|
||||
public void setControllerAutoShow(boolean controllerAutoShow) {
|
||||
this.controllerAutoShow = controllerAutoShow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link PlaybackControlView.VisibilityListener}.
|
||||
*
|
||||
|
|
@ -664,18 +708,34 @@ public final class SimpleExoPlayerView extends FrameLayout {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the playback controls, but only if forced or shown indefinitely.
|
||||
*/
|
||||
private void maybeShowController(boolean isForced) {
|
||||
if (!useController || player == null) {
|
||||
return;
|
||||
if (useController) {
|
||||
boolean wasShowingIndefinitely = controller.isVisible() && controller.getShowTimeoutMs() <= 0;
|
||||
boolean shouldShowIndefinitely = shouldShowControllerIndefinitely();
|
||||
if (isForced || wasShowingIndefinitely || shouldShowIndefinitely) {
|
||||
showController(shouldShowIndefinitely);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldShowControllerIndefinitely() {
|
||||
if (player == null) {
|
||||
return true;
|
||||
}
|
||||
int playbackState = player.getPlaybackState();
|
||||
boolean showIndefinitely = playbackState == ExoPlayer.STATE_IDLE
|
||||
|| playbackState == ExoPlayer.STATE_ENDED || !player.getPlayWhenReady();
|
||||
boolean wasShowingIndefinitely = controller.isVisible() && controller.getShowTimeoutMs() <= 0;
|
||||
controller.setShowTimeoutMs(showIndefinitely ? 0 : controllerShowTimeoutMs);
|
||||
if (isForced || showIndefinitely || wasShowingIndefinitely) {
|
||||
controller.show();
|
||||
return controllerAutoShow && (playbackState == ExoPlayer.STATE_IDLE
|
||||
|| playbackState == ExoPlayer.STATE_ENDED || !player.getPlayWhenReady());
|
||||
}
|
||||
|
||||
private void showController(boolean showIndefinitely) {
|
||||
if (!useController) {
|
||||
return;
|
||||
}
|
||||
controller.setShowTimeoutMs(showIndefinitely ? 0 : controllerShowTimeoutMs);
|
||||
controller.show();
|
||||
}
|
||||
|
||||
private void updateForCurrentTrackSelections() {
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@
|
|||
<attr name="default_artwork" format="reference"/>
|
||||
<attr name="use_controller" format="boolean"/>
|
||||
<attr name="hide_on_touch" format="boolean"/>
|
||||
<attr name="auto_show" format="boolean"/>
|
||||
<attr name="resize_mode"/>
|
||||
<attr name="surface_type"/>
|
||||
<attr name="show_timeout"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue