PlayerView


public class PlayerView extends FrameLayout implements AdViewProvider


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 and how it is displayed.
  • default_artwork - Default artwork to use if no artwork available in audio streams.
  • image_display_mode - The mode in which images are displayed.
  • use_controller - Whether the playback controls can be shown.
  • hide_on_touch - Whether the playback controls are hidden by touch events.
  • 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 with showController and hideController.
  • 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.
  • show_buffering - Whether the buffering spinner is displayed when the player is buffering. Valid values are never, when_playing and always.
  • resize_mode - Controls how video and album art is resized within the view. Valid values are fit, fixed_width, fixed_height, fill and zoom.
  • surface_type - The type of surface view used for video playbacks. Valid values are surface_view, texture_view, spherical_gl_surface_view, video_decoder_gl_surface_view and none. Using none is recommended for audio only applications, since creating the surface can be expensive. Using surface_view is 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 the exo_shutter view.
  • keep_content_on_player_reset - Whether the currently displayed video frame or media artwork is kept visible when the player is reset.
  • All attributes that can be set on PlayerControlView and DefaultTimeBar can also be set on a PlayerView, and will be propagated to the inflated .

Overriding drawables

The drawables used by PlayerControlView 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

@UnstableApi
@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation PlayerView.ArtworkDisplayMode

Determines the artwork display mode.

Listener to be notified about changes of the visibility of the UI controls.

Listener invoked when the fullscreen button is clicked.

@UnstableApi
@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation PlayerView.ImageDisplayMode

Determines the image display mode.

@UnstableApi
@Documented
@Retention(value = RetentionPolicy.SOURCE)
@Target(value = TYPE_USE)
@IntDef(value = )
public annotation PlayerView.ShowBuffering

Determines 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 buffering state.

static final int

The buffering view is never shown.

static final int

The buffering view is shown when the player is in the buffering state and playWhenReady is true.

Public constructors

PlayerView(
    Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

boolean
boolean

Called to process media key events.

List<AdOverlayInfo>

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.

ViewGroup

Returns the ViewGroup on top of the player that will show any ad UI, or null if playing audio-only ads.

int

Returns the artwork display mode.

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 image display mode.

@Nullable FrameLayout

Gets the overlay FrameLayout, which can be populated with UI elements to show on top of the player.

@Nullable Player

Returns the player currently set on this view, or null if no player is set.

int

Returns the ResizeMode.

@Nullable SubtitleView

Gets the SubtitleView.

boolean

This method is deprecated.

Use getArtworkDisplayMode instead.

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

Should be called when the player is no longer visible to the user, if the surface_type extends GLSurfaceView.

void

Should be called when the player is visible to the user, if the surface_type extends GLSurfaceView.

boolean
boolean
void

Sets whether and how artwork is displayed if present in the media.

void

Sets the AspectRatioFrameLayout.AspectRatioListener.

void
@UnstableApi
setControllerAnimationEnabled(boolean animationEnabled)

Sets whether controller animation is enabled.

void
@UnstableApi
setControllerAutoShow(boolean controllerAutoShow)

Sets whether the playback controls are automatically shown when playback starts, pauses, ends, or fails.

void
@UnstableApi
setControllerHideDuringAds(boolean controllerHideDuringAds)

Sets whether the playback controls are hidden when ads are playing.

void
@UnstableApi
setControllerHideOnTouch(boolean controllerHideOnTouch)

Sets whether the playback controls are hidden by touch events.

void

This method is deprecated.

Use setFullscreenButtonClickListener instead.

void
@UnstableApi
setControllerShowTimeoutMs(int controllerShowTimeoutMs)

Sets the playback controls timeout.

void

This method is deprecated.

Use setControllerVisibilityListener instead.

void

Sets the ControllerVisibilityListener.

void

Sets a custom error message to be displayed by the view.

void

Sets the default artwork to display if useArtwork is true and no artwork is present in the media.

void
@UnstableApi
setEnableComposeSurfaceSyncWorkaround(
    boolean enableComposeSurfaceSyncWorkaround
)

Whether to enable a workaround for the Compose AndroidView and SurfaceView compatibility issue described in androidx/media#1237.

void

Sets the optional ErrorMessageProvider.

void
@UnstableApi
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.

void

Sets the FullscreenButtonClickListener.

void
@UnstableApi
setFullscreenButtonState(boolean isFullscreen)

Sets whether the player is currently in fullscreen, this will change the displayed icon.

void

Sets how images are displayed if present in the media.

void
@UnstableApi
setKeepContentOnPlayerReset(boolean keepContentOnPlayerReset)

Sets whether the currently displayed video frame or media artwork is kept visible when the player is reset.

void

Sets the Player to use.

void

Sets which repeat toggle modes are enabled.

void

Sets the ResizeMode.

void

Sets whether a buffering spinner is displayed when the player is in the buffering state.

void
@UnstableApi
setShowFastForwardButton(boolean showFastForwardButton)

Sets whether the fast forward button is shown.

void
@UnstableApi
setShowMultiWindowTimeBar(boolean showMultiWindowTimeBar)

This method is deprecated.

Replace multi-window time bar display by merging source windows together instead, for example using ExoPlayer's ConcatenatingMediaSource2.

void
@UnstableApi
setShowNextButton(boolean showNextButton)

Sets whether the next button is shown.

void
@UnstableApi
setShowPlayButtonIfPlaybackIsSuppressed(
    boolean showPlayButtonIfSuppressed
)

Sets whether a play button is shown if playback is suppressed.

void
@UnstableApi
setShowPreviousButton(boolean showPreviousButton)

Sets whether the previous button is shown.

void
@UnstableApi
setShowRewindButton(boolean showRewindButton)

Sets whether the rewind button is shown.

void
@UnstableApi
setShowShuffleButton(boolean showShuffleButton)

Sets whether the shuffle button is shown.

void
@UnstableApi
setShowSubtitleButton(boolean showSubtitleButton)

Sets whether the subtitle button is shown.

void
@UnstableApi
setShowVrButton(boolean showVrButton)

Sets whether the vr button is shown.

void

Sets the background color of the exo_shutter view.

void
@UnstableApi
setUseArtwork(boolean useArtwork)

This method is deprecated.

Use setArtworkDisplayMode instead.

void
setUseController(boolean useController)

Sets whether the playback controls can be shown.

void
setVisibility(int visibility)
void

Shows the playback controls.

static void
@UnstableApi
switchTargetView(
    Player player,
    @Nullable PlayerView oldPlayerView,
    @Nullable PlayerView newPlayerView
)

Switches the view targeted by a given Player.

Protected methods

void
void
@UnstableApi
onContentAspectRatioChanged(
    @Nullable AspectRatioFrameLayout contentFrame,
    float aspectRatio
)

Called when there's a change in the desired aspect ratio of the content frame.

Inherited Constants

From android.view.View
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final int
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = "creditCardExpirationDate"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = "creditCardExpirationMonth"
static final String
AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = "creditCardExpirationYear"
static final String
static final String
AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int
static final int
static final int
static final int
static final int
static final int
static final int
GONE = 8
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
KEEP_SCREEN_ON = 67108864
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
NO_ID = -1
static final int
static final int
static final int
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int[]
static final int[]
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
static final String
VIEW_LOG_TAG = "View"
static final int
static final int[]
static final Property<ViewFloat>
static final Property<ViewFloat>
static final Property<ViewFloat>
From android.view.ViewGroup
static final int
static final int
static final int
static final int
static final int
static final int
static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

static final int

This field is deprecated.

Inherited methods

From android.widget.FrameLayout
boolean
FrameLayout.LayoutParams
FrameLayout.LayoutParams
CharSequence
boolean

This method is deprecated.

boolean
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
setForegroundGravity(int foregroundGravity)
void
setMeasureAllChildren(boolean measureAll)
boolean
From android.view.View
void
void
void
ViewPropertyAnimator
void
void
boolean
void
void

This method is deprecated.

void
boolean
boolean
boolean
boolean
boolean
canScrollHorizontally(int direction)
boolean
canScrollVertically(int direction)
final void
void
final void
boolean
void
void
static int
combineMeasuredStates(int curState, int newState)
int
int
int
void
WindowInsets
int
int
int
AccessibilityNodeInfo
void
void

This method is deprecated.

boolean
boolean
dispatchNestedFling(float velocityX, float velocityY, boolean consumed)
boolean
dispatchNestedPreFling(float velocityX, float velocityY)
boolean
dispatchNestedPrePerformAccessibilityAction(
    int action,
    Bundle arguments
)
boolean
dispatchNestedPreScroll(
    int dx,
    int dy,
    int[] consumed,
    int[] offsetInWindow
)
boolean
dispatchNestedScroll(
    int dxConsumed,
    int dyConsumed,
    int dxUnconsumed,
    int dyUnconsumed,
    int[] offsetInWindow
)
boolean
void
draw(Canvas canvas)
void
drawableHotspotChanged(float x, float y)
final OnBackInvokedDispatcher
final T
<T extends View> findViewById(int id)
final T
<T extends View> findViewWithTag(Object tag)
boolean

This method is deprecated.

void
forceHasOverlappingRendering(boolean hasOverlappingRendering)
void
void
generateDisplayHash(
    String hashAlgorithm,
    Rect bounds,
    Executor executor,
    DisplayHashResultCallback callback
)
static int
View.AccessibilityDelegate
int
AccessibilityNodeProvider
CharSequence
int
int
String
String
float
Animation
Matrix
IBinder
int[]
Map<IntegerInteger>
String[]
final AutofillId
int
AutofillValue