LegacyPlayerControlView
@UnstableApi
class LegacyPlayerControlView : FrameLayout
| kotlin.Any | ||||
| ↳ | android.view.View | |||
| ↳ | android.view.ViewGroup | |||
| ↳ | android.widget.FrameLayout | |||
| ↳ | androidx.media3.ui.LegacyPlayerControlView |
A view for controlling Player instances.
A LegacyPlayerControlView can be customized by setting attributes (or calling corresponding methods), overriding drawables, overriding the view's layout file, or by specifying a custom view layout file.
Attributes
The following attributes can be set on a LegacyPlayerControlView when used in a layout XML file:show_timeout- The time between the last user interaction and the controls being automatically hidden, in milliseconds. Use zero if the controls should not automatically timeout.- Corresponding method:
setShowTimeoutMs - Default:
DEFAULT_SHOW_TIMEOUT_MS
- Corresponding method:
show_rewind_button- Whether the rewind button is shown.- Corresponding method:
setShowRewindButton - Default: true
- Corresponding method:
show_fastforward_button- Whether the fast forward button is shown.- Corresponding method:
setShowFastForwardButton - Default: true
- Corresponding method:
show_previous_button- Whether the previous button is shown.- Corresponding method:
setShowPreviousButton - Default: true
- Corresponding method:
show_next_button- Whether the next button is shown.- Corresponding method:
setShowNextButton - Default: true
- Corresponding method:
repeat_toggle_modes- A flagged enumeration value specifying which repeat mode toggle options are enabled. Valid values are:none,one,all, orone|all.- Corresponding method:
setRepeatToggleModes - Default:
DEFAULT_REPEAT_TOGGLE_MODES
- Corresponding method:
show_shuffle_button- Whether the shuffle button is shown.- Corresponding method:
setShowShuffleButton - Default: false
- Corresponding method:
time_bar_min_update_interval- Specifies the minimum interval between time bar position updates.- Corresponding method:
setTimeBarMinUpdateInterval - Default:
DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS
- Corresponding method:
controller_layout_id- Specifies the id of the layout to be inflated. See below for more details.- Corresponding method: None
- Default:
R.layout.exo_legacy_player_control_view
- All attributes that can be set on
DefaultTimeBarcan also be set on a LegacyPlayerControlView, and will be propagated to the inflatedDefaultTimeBarunless the layout is overridden to specify a customexo_progress(see below).
Overriding drawables
The drawables used by LegacyPlayerControlView (with its default layout file) can be overridden by drawables with the same names defined in your application. The drawables that can be overridden are:exo_legacy_controls_play- The play icon.exo_legacy_controls_pause- The pause icon.exo_legacy_controls_rewind- The rewind icon.exo_legacy_controls_fastforward- The fast forward icon.exo_legacy_controls_previous- The previous icon.exo_legacy_controls_next- The next icon.exo_legacy_controls_repeat_off- The repeat icon forREPEAT_MODE_OFF.exo_legacy_controls_repeat_one- The repeat icon forREPEAT_MODE_ONE.exo_legacy_controls_repeat_all- The repeat icon forREPEAT_MODE_ALL.exo_legacy_controls_shuffle_off- The shuffle icon when shuffling is disabled.exo_legacy_controls_shuffle_on- The shuffle icon when shuffling is enabled.exo_legacy_controls_vr- The VR icon.
Overriding the layout file
To customize the layout of LegacyPlayerControlView throughout your app, or just for certain configurations, you can defineexo_legacy_player_control_view.xml layout files in your application res/layout* directories. These layouts will override the one provided by the library, and will be inflated for use by LegacyPlayerControlView. The view identifies and binds its children by looking for the following ids:
exo_play- The play button.- Type:
View
- Type:
exo_pause- The pause button.- Type:
View
- Type:
exo_rew- The rewind button.- Type:
View
- Type:
exo_ffwd- The fast forward button.- Type:
View
- Type:
exo_prev- The previous button.- Type:
View
- Type:
exo_next- The next button.- Type:
View
- Type:
exo_repeat_toggle- The repeat toggle button.- Type:
ImageView - Note: LegacyPlayerControlView will programmatically set the drawable on the repeat toggle button according to the player's current repeat mode. The drawables used are
exo_legacy_controls_repeat_off,exo_legacy_controls_repeat_oneandexo_legacy_controls_repeat_all. See the section above for information on overriding these drawables.
- Type:
exo_shuffle- The shuffle button.- Type:
ImageView - Note: LegacyPlayerControlView will programmatically set the drawable on the shuffle button according to the player's current repeat mode. The drawables used are
exo_legacy_controls_shuffle_offandexo_legacy_controls_shuffle_on. See the section above for information on overriding these drawables.
- Type:
exo_vr- The VR mode button.- Type:
View
- Type:
exo_position- Text view displaying the current playback position.- Type:
TextView
- Type:
exo_duration- Text view displaying the current media duration.- Type:
TextView
- Type:
exo_progress_placeholder- A placeholder that's replaced with the inflatedDefaultTimeBar. Ignored if anexo_progressview exists.- Type:
View
- Type:
exo_progress- Time bar that's updated during playback and allows seeking.DefaultTimeBarattributes set on the LegacyPlayerControlView will not be automatically propagated through to this instance. If a view exists with this id, anyexo_progress_placeholderview will be ignored.- Type:
TimeBar
- Type:
All child views are optional and so can be omitted if not required, however where defined they must be of the expected type.
Specifying a custom layout file
Defining your ownexo_legacy_player_control_view.xml is useful to customize the layout of LegacyPlayerControlView throughout your application. It's also possible to customize the layout for a single instance in a layout file. This is achieved by setting the
controller_layout_id attribute on a LegacyPlayerControlView. This will cause the specified layout to be inflated instead of exo_legacy_player_control_view.xml for only the instance on which the attribute is set.
Summary
Nested types |
|---|
|
Listener to be notified when progress has been updated. |
|
Listener to be notified about changes of the visibility of the UI control. |
Constants |
|
|---|---|
const Int |
The default repeat toggle modes. |
const Int |
DEFAULT_SHOW_TIMEOUT_MS = 5000The default show timeout, in milliseconds. |
const Int |
The default minimum interval between time bar position updates. |
const Int |
The maximum number of windows that can be shown in a multi-window time bar. |
Public constructors |
|---|
LegacyPlayerControlView(context: Context!) |
LegacyPlayerControlView(context: Context!, attrs: AttributeSet?) |
LegacyPlayerControlView( |
LegacyPlayerControlView( |
Public functions |
|
|---|---|
Unit |
Adds a |
Boolean |
dispatchKeyEvent(event: KeyEvent!) |
Boolean |
dispatchMediaKeyEvent(event: KeyEvent!)Called to process media key events. |
Boolean |
|
Boolean |
Returns whether the VR button is shown. |
Unit |
hide()Hides the controller. |
Boolean |
Returns whether the controller is currently visible. |
Unit |
|
Unit |
|
Unit |
Removes a |
Unit |
setExtraAdGroupMarkers(Sets the millisecond positions of extra ad markers relative to the start of the window (or timeline, if in multi-window mode) and whether each extra ad has been played or not. |
Unit |
Sets the |
Unit |
setShowFastForwardButton(showFastForwardButton: Boolean)Sets whether the fast forward button is shown. |
Unit |
This function is deprecated. Replace multi-window time bar display by merging source windows together instead, for example using ExoPlayer's |
Unit |
setShowNextButton(showNextButton: Boolean)Sets whether the next button is shown. |
Unit |
setShowPlayButtonIfPlaybackIsSuppressed(Sets whether a play button is shown if playback is |
Unit |
setShowPreviousButton(showPreviousButton: Boolean)Sets whether the previous button is shown. |
Unit |
setShowRewindButton(showRewindButton: Boolean)Sets whether the rewind button is shown. |
Unit |
setShowVrButton(showVrButton: Boolean)Sets whether the VR button is shown. |
Unit |
setTimeBarMinUpdateInterval(minUpdateIntervalMs: Int)Sets the minimum interval between time bar position updates. |
Unit |
setVrButtonListener(onClickListener: View.OnClickListener?)Sets listener for the VR button. |
Unit |
show()Shows the playback controls. |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
DEFAULT_REPEAT_TOGGLE_MODES
@RepeatModeUtil.RepeatToggleModes
const val DEFAULT_REPEAT_TOGGLE_MODES = 0: Int
The default repeat toggle modes.
DEFAULT_SHOW_TIMEOUT_MS
const val DEFAULT_SHOW_TIMEOUT_MS = 5000: Int
The default show timeout, in milliseconds.
DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS
const val DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS = 200: Int
The default minimum interval between time bar position updates.
MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR
const val MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR = 100: Int
The maximum number of windows that can be shown in a multi-window time bar.
Public constructors
LegacyPlayerControlView
LegacyPlayerControlView(
context: Context!,
attrs: AttributeSet?,
defStyleAttr: Int
)
LegacyPlayerControlView
LegacyPlayerControlView(
context: Context!,
attrs: AttributeSet?,
defStyleAttr: Int,
playbackAttrs: AttributeSet?
)
Public functions
addVisibilityListener
fun addVisibilityListener(
listener: LegacyPlayerControlView.VisibilityListener!
): Unit
Adds a VisibilityListener.
| Parameters | |
|---|---|
listener: LegacyPlayerControlView.VisibilityListener! |
The listener to be notified about visibility changes. |
dispatchMediaKeyEvent
fun dispatchMediaKeyEvent(event: KeyEvent!): Boolean
Called to process media key events. Any KeyEvent can be passed but only media key events will be handled.
| Parameters | |
|---|---|
event: KeyEvent! |
A key event. |
| Returns | |
|---|---|
Boolean |
Whether the key event was handled. |
removeVisibilityListener
fun removeVisibilityListener(
listener: LegacyPlayerControlView.VisibilityListener!
): Unit
Removes a VisibilityListener.
| Parameters | |
|---|---|
listener: LegacyPlayerControlView.VisibilityListener! |
The listener to be removed. |
setExtraAdGroupMarkers
fun setExtraAdGroupMarkers(
extraAdGroupTimesMs: LongArray?,
extraPlayedAdGroups: BooleanArray?
): Unit
Sets the millisecond positions of extra ad markers relative to the start of the window (or timeline, if in multi-window mode) and whether each extra ad has been played or not. The markers are shown in addition to any ad markers for ads in the player's timeline.
| Parameters | |
|---|---|
extraAdGroupTimesMs: LongArray? |
The millisecond timestamps of the extra ad markers to show, or |
extraPlayedAdGroups: BooleanArray? |
Whether each ad has been played. Must be the same length as |
setProgressUpdateListener
fun setProgressUpdateListener(
listener: LegacyPlayerControlView.ProgressUpdateListener?
): Unit
Sets the ProgressUpdateListener.
| Parameters | |
|---|---|
listener: LegacyPlayerControlView.ProgressUpdateListener? |
The listener to be notified about when progress is updated. |
setShowFastForwardButton
fun setShowFastForwardButton(showFastForwardButton: Boolean): Unit
Sets whether the fast forward button is shown.
| Parameters | |
|---|---|
showFastForwardButton: Boolean |
Whether the fast forward button is shown. |
setShowNextButton
fun setShowNextButton(showNextButton: Boolean): Unit
Sets whether the next button is shown.
| Parameters | |
|---|---|
showNextButton: Boolean |
Whether the next button is shown. |
setShowPlayButtonIfPlaybackIsSuppressed
fun setShowPlayButtonIfPlaybackIsSuppressed(
showPlayButtonIfSuppressed: Boolean
): Unit
Sets whether a play button is shown if playback is suppressed.
The default is true.
| Parameters | |
|---|---|
showPlayButtonIfSuppressed: Boolean |
Whether to show a play button if playback is |
setShowPreviousButton
fun setShowPreviousButton(showPreviousButton: Boolean): Unit
Sets whether the previous button is shown.
| Parameters | |
|---|---|
showPreviousButton: Boolean |
Whether the previous button is shown. |
setShowRewindButton
fun setShowRewindButton(showRewindButton: Boolean): Unit
Sets whether the rewind button is shown.
| Parameters | |
|---|---|
showRewindButton: Boolean |
Whether the rewind button is shown. |
setShowVrButton
fun setShowVrButton(showVrButton: Boolean): Unit
Sets whether the VR button is shown.
| Parameters | |
|---|---|
showVrButton: Boolean |
Whether the VR button is shown. |
setTimeBarMinUpdateInterval
fun setTimeBarMinUpdateInterval(minUpdateIntervalMs: Int): Unit
Sets the minimum interval between time bar position updates.
Note that smaller intervals, e.g. 33ms, will result in a smooth movement but will use more CPU resources while the time bar is visible, whereas larger intervals, e.g. 200ms, will result in a step-wise update with less CPU usage.
| Parameters | |
|---|---|
minUpdateIntervalMs: Int |
The minimum interval between time bar position updates, in milliseconds. |
setVrButtonListener
fun setVrButtonListener(onClickListener: View.OnClickListener?): Unit
Sets listener for the VR button.
| Parameters | |
|---|---|
onClickListener: View.OnClickListener? |
Listener for the VR button, or null to clear the listener. |
show
fun show(): Unit
Shows the playback controls. If getShowTimeoutMs is positive then the controls will be automatically hidden after this duration of time has elapsed without user input.