PlayerView
public class PlayerView extends FrameLayout implements AdViewProvider
| java.lang.Object | ||||
| ↳ | android.view.View | |||
| ↳ | android.view.ViewGroup | |||
| ↳ | android.widget.FrameLayout | |||
| ↳ | androidx.media3.ui.PlayerView |
A high level view for Player media playbacks. It displays video, subtitles and album art during playback, and displays playback controls using a PlayerControlView.
A PlayerView can be customized by setting attributes (or calling corresponding methods), or overriding drawables.
Attributes
The following attributes can be set on a PlayerView when used in a layout XML file:artwork_display_mode- Whether artwork is used if available in audio streams andhow it is displayed.- Corresponding method:
setArtworkDisplayMode - Default:
ARTWORK_DISPLAY_MODE_FIT
- Corresponding method:
default_artwork- Default artwork to use if no artwork available in audio streams.- Corresponding method:
setDefaultArtwork - Default:
null
- Corresponding method:
image_display_mode- Themodein which images are displayed.- Corresponding method:
setImageDisplayMode - Default:
#IMAGE_DISPLAY_MODE_FIT
- Corresponding method:
use_controller- Whether the playback controls can be shown.- Corresponding method:
setUseController - Default:
true
- Corresponding method:
hide_on_touch- Whether the playback controls are hidden by touch events.- Corresponding method:
setControllerHideOnTouch - Default:
true
- Corresponding method:
auto_show- 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 withshowControllerandhideController.- Corresponding method:
setControllerAutoShow - Default:
true
- Corresponding method:
hide_during_ads- Whether the playback controls are hidden during ads. Controls are always shown during ads if they are enabled and the player is paused.- Corresponding method:
setControllerHideDuringAds - Default:
true
- Corresponding method:
show_buffering- Whether the buffering spinner is displayed when the player is buffering. Valid values arenever,when_playingandalways.- Corresponding method:
setShowBuffering - Default:
never
- Corresponding method:
resize_mode- Controls how video and album art is resized within the view. Valid values arefit,fixed_width,fixed_height,fillandzoom.- Corresponding method:
setResizeMode - Default:
fit
- Corresponding method:
surface_type- The type of surface view used for video playbacks. Valid values aresurface_view,texture_view,spherical_gl_surface_view,video_decoder_gl_surface_viewandnone. Usingnoneis recommended for audio only applications, since creating the surface can be expensive. Usingsurface_viewis recommended for video applications. See Choosing a surface type for more information.- Corresponding method: None
- Default:
surface_view
shutter_background_color- The background color of theexo_shutterview.- Corresponding method:
setShutterBackgroundColor - Default:
unset
- Corresponding method:
keep_content_on_player_reset- Whether the currently displayed video frame or media artwork is kept visible when the player is reset.- Corresponding method:
setKeepContentOnPlayerReset - Default:
false
- Corresponding method:
- All attributes that can be set on
PlayerControlViewandDefaultTimeBarcan also be set on a PlayerView, and will be propagated to the inflatedPlayerControlView.
Overriding drawables
The drawables used byPlayerControlView can be overridden by drawables with the same names defined in your application. See the PlayerControlView documentation for a list of drawables that can be overridden.
Summary
Nested types |
|---|
@UnstableApiDetermines the artwork display mode. |
public interface PlayerView.ControllerVisibilityListenerListener to be notified about changes of the visibility of the UI controls. |
public interface PlayerView.FullscreenButtonClickListenerListener invoked when the fullscreen button is clicked. |
@UnstableApiDetermines the image display mode. |
@UnstableApiDetermines when the buffering view is shown. |
Constants |
|
|---|---|
static final int |
The artwork covers the entire space of the player view. |
static final int |
The artwork is fit into the player view and centered creating a letterbox style. |
static final int |
No artwork is shown. |
static final int |
The image covers the entire space of the player view. |
static final int |
The image is fit into the player view and centered creating a letterbox style. |
static final int |
The buffering view is always shown when the player is in the |
static final int |
The buffering view is never shown. |
static final int |
The buffering view is shown when the player is in the |
Public fields |
|
|---|---|
int |
|
boolean |
|
boolean |
|
int |
|
@Nullable Drawable |
|
int |
|
final @Nullable FrameLayout |
|
@Nullable Player |
|
final @Nullable SubtitleView |
|
boolean |
Public constructors |
|---|
PlayerView(Context context) |
PlayerView(Context context, @Nullable AttributeSet attrs) |
PlayerView( |
Public methods |
|
|---|---|
boolean |
dispatchKeyEvent(KeyEvent event) |
boolean |
Called to process media key events. |
List<AdOverlayInfo> |
Returns a list of |
ViewGroup |
Returns the |
int |
Returns the |
boolean |
Returns whether the playback controls are automatically shown when playback starts, pauses, ends, or fails. |
boolean |
Returns whether the playback controls are hidden by touch events. |
int |
Returns the playback controls timeout. |
@Nullable Drawable |
Returns the default artwork to display. |
int |
Returns the |
@Nullable FrameLayout |
Gets the overlay |
@Nullable Player |
Returns the player currently set on this view, or null if no player is set. |
int |
Returns the |
@Nullable SubtitleView |
Gets the |
boolean |
This method is deprecated. Use |
boolean |
Returns whether the playback controls can be shown. |
@Nullable View |
Gets the view onto which video is rendered. |
void |
Hides the playback controls. |
boolean |
Returns whether the controller is currently fully visible. |
void |
onPause()Should be called when the player is no longer visible to the user, if the |
void |
onResume()Should be called when the player is visible to the user, if the |
boolean |
|
boolean |
|
void |
@UnstableApiSets whether and how artwork is displayed if present in the media. |
void |
|
void |
@UnstableApiSets whether |
void |
@UnstableApiSets whether the playback controls are automatically shown when playback starts, pauses, ends, or fails. |
void |
@UnstableApiSets whether the playback controls are hidden when ads are playing. |
void |
@UnstableApiSets whether the playback controls are hidden by touch events. |
void |
@UnstableApiThis method is deprecated. Use |
void |
@UnstableApiSets the playback controls timeout. |
void |
@UnstableApiThis method is deprecated. Use |
void |
Sets the |
void |
@UnstableApiSets a custom error message to be displayed by the view. |
void |
@UnstableApiSets the default artwork to display if |
void |
@UnstableApiWhether to enable a workaround for the Compose |
void |
setErrorMessageProvider(Sets the optional |
void |
@UnstableApiSets 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. |
void |
Sets the |
void |
@UnstableApiSets whether the player is currently in fullscreen, this will change the displayed icon. |
void |
@UnstableApiSets how images are displayed if present in the media. |
void |
@UnstableApiSets whether the currently displayed video frame or media artwork is kept visible when the player is reset. |
void |
@UnstableApiSets a |
void |
Sets the |
void |
@UnstableApiSets which repeat toggle modes are enabled. |
void |
@UnstableApiSets the |
void |
@UnstableApiSets whether a buffering spinner is displayed when the player is in the buffering state. |
void |
@UnstableApiSets whether the fast forward button is shown. |
void |
@UnstableApiThis method is deprecated. Replace multi-window time bar display by merging source windows together instead, for example using ExoPlayer's |
void |
@UnstableApiSets whether the next button is shown. |
void |
@UnstableApiSets whether a play button is shown if playback is |
void |
@UnstableApiSets whether the previous button is shown. |
void |
@UnstableApiSets whether the rewind button is shown. |
void |
@UnstableApiSets whether the shuffle button is shown. |
void |
@UnstableApiSets whether the subtitle button is shown. |
void |
@UnstableApiSets whether the vr button is shown. |
void |
@UnstableApiSets the background color of the |
void |
@UnstableApiSets whether the time bar should seek immediately as the user drags the scrubber around (true), or only seek when the user releases the scrubber (false). |
void |
@UnstableApiThis method is deprecated. Use |
void |
setUseController(boolean useController)Sets whether the playback controls can be shown. |
void |
setVisibility(int visibility) |
void |
Shows the playback controls. |
static void |
@UnstableApiSwitches the view targeted by a given |
Protected methods |
|
|---|---|
void |
dispatchDraw(Canvas canvas) |
void |
@UnstableApiCalled when there's a change in the desired aspect ratio of the content frame. |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Inherited methods |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Constants
ARTWORK_DISPLAY_MODE_FILL
@UnstableApi
public static final int ARTWORK_DISPLAY_MODE_FILL = 2
The artwork covers the entire space of the player view. If the aspect ratio of the image is different than the player view some areas of the image are cropped.
ARTWORK_DISPLAY_MODE_FIT
@UnstableApi
public static final int ARTWORK_DISPLAY_MODE_FIT = 1
The artwork is fit into the player view and centered creating a letterbox style.
ARTWORK_DISPLAY_MODE_OFF
@UnstableApi
public static final int ARTWORK_DISPLAY_MODE_OFF = 0
No artwork is shown.
IMAGE_DISPLAY_MODE_FILL
@UnstableApi
public static final int IMAGE_DISPLAY_MODE_FILL = 1
The image covers the entire space of the player view. If the aspect ratio of the image is different than the player view some areas of the image are cropped.
IMAGE_DISPLAY_MODE_FIT
@UnstableApi
public static final int IMAGE_DISPLAY_MODE_FIT = 0
The image is fit into the player view and centered creating a letterbox style.
SHOW_BUFFERING_ALWAYS
@UnstableApi
public static final int SHOW_BUFFERING_ALWAYS = 2
The buffering view is always shown when the player is in the buffering state.
SHOW_BUFFERING_NEVER
@UnstableApi
public static final int SHOW_BUFFERING_NEVER = 0
The buffering view is never shown.
SHOW_BUFFERING_WHEN_PLAYING
@UnstableApi
public static final int SHOW_BUFFERING_WHEN_PLAYING = 1
The buffering view is shown when the player is in the buffering state and playWhenReady is true.
Public fields
Public constructors
Public methods
dispatchMediaKeyEvent
@UnstableApi
public boolean dispatchMediaKeyEvent(KeyEvent event)
Called to process media key events. Any KeyEvent can be passed but only media key events will be handled. Does nothing if playback controls are disabled.
| Parameters | |
|---|---|
KeyEvent event |
A key event. |
| Returns | |
|---|---|
boolean |
Whether the key event was handled. |
getAdOverlayInfos
public List<AdOverlayInfo> getAdOverlayInfos()
Returns a list of AdOverlayInfo instances describing views that are on top of the ad view group, but that are essential for controlling playback and should be excluded from ad viewability measurements.
Each view must be either a fully transparent overlay (for capturing touch events), or a small piece of transient UI that is essential to the user experience of playback (such as a button to pause/resume playback or a transient full-screen or cast button). For more information see the documentation for your ads loader.
getAdViewGroup
public ViewGroup getAdViewGroup()
Returns the ViewGroup on top of the player that will show any ad UI, or null if playing audio-only ads. Any views on top of the returned view group must be described by AdOverlayInfos returned by getAdOverlayInfos, for accurate viewability measurement.
getArtworkDisplayMode
@UnstableApi
@PlayerView.ArtworkDisplayMode
public int getArtworkDisplayMode()
Returns the artwork display mode.
getControllerAutoShow
@UnstableApi
public boolean getControllerAutoShow()
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 showController and hideController.
getControllerHideOnTouch
@UnstableApi
public boolean getControllerHideOnTouch()
Returns whether the playback controls are hidden by touch events.
getControllerShowTimeoutMs
@UnstableApi
public int getControllerShowTimeoutMs()
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 progress.
| Returns | |
|---|---|
int |
The timeout in milliseconds. A non-positive value will cause the controller to remain visible indefinitely. |
getDefaultArtwork
@UnstableApi
public @Nullable Drawable getDefaultArtwork()
Returns the default artwork to display.
getImageDisplayMode
@UnstableApi
@PlayerView.ImageDisplayMode
public int getImageDisplayMode()
Returns the image display mode.
getOverlayFrameLayout
@UnstableApi
public @Nullable FrameLayout getOverlayFrameLayout()
Gets the overlay FrameLayout, which can be populated with UI elements to show on top of the player.
| Returns | |
|---|---|
@Nullable FrameLayout |
The overlay |
getPlayer
public @Nullable Player getPlayer()
Returns the player currently set on this view, or null if no player is set.
getResizeMode
@UnstableApi
@AspectRatioFrameLayout.ResizeMode
public int getResizeMode()
Returns the ResizeMode.
getSubtitleView
@UnstableApi
public @Nullable SubtitleView getSubtitleView()
Gets the SubtitleView.
| Returns | |
|---|---|
@Nullable SubtitleView |
The |
getUseController
public boolean getUseController()
Returns whether the playback controls can be shown.
getVideoSurfaceView
@UnstableApi
public @Nullable View getVideoSurfaceView()
Gets the view onto which video is rendered. This is a:
SurfaceViewby default, or if thesurface_typeattribute is set tosurface_view.TextureViewifsurface_typeistexture_view.SphericalGLSurfaceViewifsurface_typeisspherical_gl_surface_view.VideoDecoderGLSurfaceViewifsurface_typeisvideo_decoder_gl_surface_view.nullifsurface_typeisnone.
| Returns | |
|---|---|
@Nullable View |
The |
hideController
@UnstableApi
public void hideController()
Hides the playback controls. Does nothing if playback controls are disabled.
isControllerFullyVisible
@UnstableApi
public boolean isControllerFullyVisible()
Returns whether the controller is currently fully visible.
onPause
public void onPause()
Should be called when the player is no longer visible to the user, if the surface_type extends GLSurfaceView. It is the counterpart to onResume.
This method should typically be called in Activity.onStop(), or
Activity.onPause() for API versions <= 23.
onResume
public void onResume()
Should be called when the player is visible to the user, if the surface_type extends GLSurfaceView. It is the counterpart to onPause.
This method should typically be called in Activity.onStart(), or
Activity.onResume() for API versions <= 23.
setArtworkDisplayMode
@UnstableApi
public void setArtworkDisplayMode(
@PlayerView.ArtworkDisplayMode int artworkDisplayMode
)
Sets whether and how artwork is displayed if present in the media.
setAspectRatioListener
@UnstableApi
public void setAspectRatioListener(
@Nullable AspectRatioFrameLayout.AspectRatioListener listener
)
Sets the AspectRatioFrameLayout.AspectRatioListener.
| Parameters | |
|---|---|
@Nullable AspectRatioFrameLayout.AspectRatioListener listener |
The listener to be notified about aspect ratios changes of the video content or the content frame. |
setControllerAnimationEnabled
@UnstableApi
public void setControllerAnimationEnabled(boolean animationEnabled)
Sets whether controller animation is enabled.
setControllerAutoShow
@UnstableApi
public void setControllerAutoShow(boolean 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 showController and hideController.
| Parameters | |
|---|---|
boolean controllerAutoShow |
Whether the playback controls are allowed to show automatically. |
setControllerHideDuringAds
@UnstableApi
public void setControllerHideDuringAds(boolean controllerHideDuringAds)
Sets whether the playback controls are hidden when ads are playing. Controls are always shown during ads if they are enabled and the player is paused.
| Parameters | |
|---|---|
boolean controllerHideDuringAds |
Whether the playback controls are hidden when ads are playing. |
setControllerHideOnTouch
@UnstableApi
public void setControllerHideOnTouch(boolean controllerHideOnTouch)
Sets whether the playback controls are hidden by touch events.
| Parameters | |
|---|---|
boolean controllerHideOnTouch |
Whether the playback controls are hidden by touch events. |
setControllerOnFullScreenModeChangedListener
@UnstableApi
public voidsetControllerOnFullScreenModeChangedListener(
@Nullable PlayerControlView.OnFullScreenModeChangedListener listener
)
Sets the PlayerControlView.OnFullScreenModeChangedListener.
Clears any listener set by setFullscreenButtonClickListener.
| Parameters | |
|---|---|
@Nullable PlayerControlView.OnFullScreenModeChangedListener listener |
The listener to be notified when the fullscreen button is clicked, or null to remove the current listener and hide the fullscreen button. |
setControllerShowTimeoutMs
@UnstableApi
public void setControllerShowTimeoutMs(int controllerShowTimeoutMs)
Sets 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 progress.
| Parameters | |
|---|---|
int controllerShowTimeoutMs |
The timeout in milliseconds. A non-positive value will cause the controller to remain visible indefinitely. |
setControllerVisibilityListener
@UnstableApi
public voidsetControllerVisibilityListener(
@Nullable PlayerControlView.VisibilityListener listener
)
Sets the PlayerControlView.VisibilityListener.
If listener is non-null then any listener set by setControllerVisibilityListener is removed.
setControllerVisibilityListener
public void setControllerVisibilityListener(
@Nullable PlayerView.ControllerVisibilityListener listener
)
Sets the ControllerVisibilityListener.
If listener is non-null then any listener set by setControllerVisibilityListener is removed.
| Parameters | |
|---|---|
@Nullable PlayerView.ControllerVisibilityListener listener |
The listener to be notified about visibility changes, or null to remove the current listener. |
setCustomErrorMessage
@UnstableApi
public void setCustomErrorMessage(@Nullable CharSequence message)
Sets a custom error message to be displayed by the view. The error message will be displayed permanently, unless it is cleared by passing null to this method.
| Parameters | |
|---|---|
@Nullable CharSequence message |
The message to display, or |
setDefaultArtwork
@UnstableApi
public void setDefaultArtwork(@Nullable Drawable defaultArtwork)
Sets the default artwork to display if useArtwork is true and no artwork is present in the media.
setEnableComposeSurfaceSyncWorkaround
@UnstableApi
public void setEnableComposeSurfaceSyncWorkaround(
boolean enableComposeSurfaceSyncWorkaround
)
Whether to enable a workaround for the Compose AndroidView and SurfaceView compatibility issue described in androidx/media#1237.
This workaround causes issues with shared element transitions in XML views, so is disabled by default (androidx/media#1594).
setErrorMessageProvider
public void setErrorMessageProvider(
@Nullable ErrorMessageProvider<PlaybackException> errorMessageProvider
)
Sets the optional ErrorMessageProvider.
| Parameters | |
|---|---|
@Nullable ErrorMessageProvider<PlaybackException> errorMessageProvider |
The error message provider. |
setExtraAdGroupMarkers
@UnstableApi
public void setExtraAdGroupMarkers(
@Nullable long[] extraAdGroupTimesMs,
@Nullable boolean[] extraPlayedAdGroups
)
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.
setFullscreenButtonClickListener
public void setFullscreenButtonClickListener(
@Nullable PlayerView.FullscreenButtonClickListener listener
)
Sets the FullscreenButtonClickListener.
Clears any listener set by setControllerOnFullScreenModeChangedListener.
| Parameters | |
|---|---|
@Nullable PlayerView.FullscreenButtonClickListener listener |
The listener to be notified when the fullscreen button is clicked, or null to remove the current listener and hide the fullscreen button. |
setFullscreenButtonState
@UnstableApi
public void setFullscreenButtonState(boolean isFullscreen)
Sets whether the player is currently in fullscreen, this will change the displayed icon.
If isFullscreen is true, @drawable/exo_styled_controls_fullscreen_exit will be displayed or else @drawable/exo_styled_controls_fullscreen_enter.
| Parameters | |
|---|---|
boolean isFullscreen |
Whether the player is currently in fullscreen. |
setImageDisplayMode
@UnstableApi
public void setImageDisplayMode(@PlayerView.ImageDisplayMode int imageDisplayMode)
Sets how images are displayed if present in the media.
setKeepContentOnPlayerReset
@UnstableApi
public void setKeepContentOnPlayerReset(boolean keepContentOnPlayerReset)
Sets whether the currently displayed video frame or media artwork is kept visible when the player is reset. A player reset is defined to mean the player being re-prepared with different media, the player transitioning to unprepared media or an empty list of media items, or the player being replaced or cleared by calling setPlayer.
If enabled, the currently displayed video frame or media artwork will be kept visible until the player set on the view has been successfully prepared with new media and loaded enough of it to have determined the available tracks. Hence enabling this option allows transitioning from playing one piece of media to another, or from using one player instance to another, without clearing the view's content.
If disabled, the currently displayed video frame or media artwork will be hidden as soon as the player is reset. Note that the video frame is hidden by making exo_shutter visible. Hence the video frame will not be hidden if using a custom layout that omits this view.
| Parameters | |
|---|---|
boolean keepContentOnPlayerReset |
Whether the currently displayed video frame or media artwork is kept visible when the player is reset. |
setMediaRouteButtonViewProvider
@UnstableApi
public void setMediaRouteButtonViewProvider(
@Nullable ViewProvider mediaRouteButtonViewProvider
)
Sets a ViewProvider to be used for creating the media route button view.
If a provider is set, this PlayerView will obtain the media route button view from the provider and display it.
If ViewProvider is null, any previously set media route button will be removed.
| Parameters | |
|---|---|
@Nullable ViewProvider mediaRouteButtonViewProvider |
The |
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the media route button fails to display due to an unexpected error. |
setPlayer
public void setPlayer(@Nullable Player player)
Sets the Player to use.
To transition a Player from targeting one view to another, it's recommended to use switchTargetView rather than this method. If you do wish to use this method directly, be sure to attach the player to the new view before calling setPlayer(null) to detach it from the old one. This ordering is significantly more efficient and may allow for more seamless transitions.
setRepeatToggleModes
@UnstableApi
public void setRepeatToggleModes(
@RepeatModeUtil.RepeatToggleModes int repeatToggleModes
)
Sets which repeat toggle modes are enabled.
| Parameters | |
|---|---|
@RepeatModeUtil.RepeatToggleModes int repeatToggleModes |
A set of |
setResizeMode
@UnstableApi
public void setResizeMode(@AspectRatioFrameLayout.ResizeMode int resizeMode)
Sets the ResizeMode.
| Parameters | |
|---|---|
@AspectRatioFrameLayout.ResizeMode int resizeMode |
The |
setShowBuffering
@UnstableApi
public void setShowBuffering(@PlayerView.ShowBuffering int showBuffering)
Sets whether a buffering spinner is displayed when the player is in the buffering state. The buffering spinner is not displayed by default.
| Parameters | |
|---|---|
@PlayerView.ShowBuffering int showBuffering |
The mode that defines when the buffering spinner is displayed. One of |
setShowFastForwardButton
@UnstableApi
public void setShowFastForwardButton(boolean showFastForwardButton)
Sets whether the fast forward button is shown.
| Parameters | |
|---|---|
boolean showFastForwardButton |
Whether the fast forward button is shown. |
setShowMultiWindowTimeBar
@UnstableApi
public voidsetShowMultiWindowTimeBar(boolean showMultiWindowTimeBar)
setShowNextButton
@UnstableApi
public void setShowNextButton(boolean showNextButton)
Sets whether the next button is shown.
| Parameters | |
|---|---|
boolean showNextButton |
Whether the next button is shown. |
setShowPlayButtonIfPlaybackIsSuppressed
@UnstableApi
public void setShowPlayButtonIfPlaybackIsSuppressed(
boolean showPlayButtonIfSuppressed
)
Sets whether a play button is shown if playback is suppressed.
The default is true.
| Parameters | |
|---|---|
boolean showPlayButtonIfSuppressed |
Whether to show a play button if playback is |
setShowPreviousButton
@UnstableApi
public void setShowPreviousButton(boolean showPreviousButton)
Sets whether the previous button is shown.
| Parameters | |
|---|---|
boolean showPreviousButton |
Whether the previous button is shown. |
setShowRewindButton
@UnstableApi
public void setShowRewindButton(boolean showRewindButton)
Sets whether the rewind button is shown.
| Parameters | |
|---|---|
boolean showRewindButton |
Whether the rewind button is shown. |
setShowShuffleButton
@UnstableApi
public void setShowShuffleButton(boolean showShuffleButton)
Sets whether the shuffle button is shown.
| Parameters | |
|---|---|
boolean showShuffleButton |
Whether the shuffle button is shown. |
setShowSubtitleButton
@UnstableApi
public void setShowSubtitleButton(boolean showSubtitleButton)
Sets whether the subtitle button is shown.
| Parameters | |
|---|---|
boolean showSubtitleButton |
Whether the subtitle button is shown. |
setShowVrButton
@UnstableApi
public void setShowVrButton(boolean showVrButton)
Sets whether the vr button is shown.
| Parameters | |
|---|---|
boolean showVrButton |
Whether the vr button is shown. |
setShutterBackgroundColor
@UnstableApi
public void setShutterBackgroundColor(@ColorInt int color)
Sets the background color of the exo_shutter view.
| Parameters | |
|---|---|
@ColorInt int color |
The background color. |
setTimeBarScrubbingEnabled
@UnstableApi
public void setTimeBarScrubbingEnabled(boolean timeBarScrubbingEnabled)
Sets whether the time bar should seek immediately as the user drags the scrubber around (true), or only seek when the user releases the scrubber (false).
This can only be used if the connected player is an instance of androidx.media3.exoplayer.ExoPlayer.
setUseController
public void setUseController(boolean useController)
Sets whether the playback controls can be shown. If set to false the playback controls are never visible and are disconnected from the player.
This call will update whether the view is clickable. After the call, the view will be clickable if playback controls can be shown or if the view has a registered click listener.
| Parameters | |
|---|---|
boolean useController |
Whether the playback controls can be shown. |
showController
@UnstableApi
public void showController()
Shows the playback controls. Does nothing if playback controls are disabled.
The playback controls are automatically hidden during playback after {getControllerShowTimeoutMs}. They are shown indefinitely when playback has not started yet, is paused, has ended or failed.
switchTargetView
@UnstableApi
public static void switchTargetView(
Player player,
@Nullable PlayerView oldPlayerView,
@Nullable PlayerView newPlayerView
)
Switches the view targeted by a given Player.
| Parameters | |
|---|---|
Player player |
The player whose target view is being switched. |
@Nullable PlayerView oldPlayerView |
The old view to detach from the player. |
@Nullable PlayerView newPlayerView |
The new view to attach to the player. |
Protected methods
onContentAspectRatioChanged
@UnstableApi
protected void onContentAspectRatioChanged(
@Nullable AspectRatioFrameLayout contentFrame,
float aspectRatio
)
Called when there's a change in the desired aspect ratio of the content frame. The default implementation sets the aspect ratio of the content frame to the specified value.
| Parameters | |
|---|---|
@Nullable AspectRatioFrameLayout contentFrame |
The content frame, or |
float aspectRatio |
The aspect ratio to apply. |