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),
overriding the view's layout file or by specifying a custom view layout file, as outlined below.
Attributes
The following attributes can be set on a PlayerView when used in a layout XML file:
-
use_artwork - Whether artwork is used if available in audio streams.
- Corresponding method:
#setUseArtwork(boolean)
- Default:
true
-
default_artwork - Default artwork to use if no artwork available in audio
streams.
- Corresponding method:
#setDefaultArtwork(Drawable)
- Default:
null
-
use_controller - Whether the playback controls can be shown.
- Corresponding method:
#setUseController(boolean)
- Default:
true
-
hide_on_touch - Whether the playback controls are hidden by touch events.
- Corresponding method:
#setControllerHideOnTouch(boolean)
- Default:
true
-
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().
- Corresponding method:
#setControllerAutoShow(boolean)
- Default:
true
-
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(boolean)
- Default:
true
-
show_buffering - Whether the buffering spinner is displayed when the player
is buffering. Valid values are
never,
when_playing and
always.
- Corresponding method:
#setShowBuffering(int)
- Default:
never
-
resize_mode - Controls how video and album art is resized within the view.
Valid values are
fit,
fixed_width,
fixed_height and
fill.
- Corresponding method:
#setResizeMode(int)
- Default:
fit
-
surface_type - The type of surface view used for video playbacks. Valid
values are
surface_view,
texture_view,
spherical_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.
Note, TextureView can only be used in a hardware accelerated window. When rendered in
software, TextureView will draw nothing.
- Corresponding method: None
- Default:
surface_view
-
shutter_background_color - The background color of the
exo_shutterview.
- Corresponding method:
#setShutterBackgroundColor(int)
- Default:
unset
-
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(boolean)
- Default:
false
-
player_layout_id - Specifies the id of the layout to be inflated. See below
for more details.
- Corresponding method: None
- Default:
R.layout.exo_player_view
-
controller_layout_id - Specifies the id of the layout resource to be
inflated by the child
PlayerControlView. See below for more details.
- Corresponding method: None
- Default:
R.layout.exo_player_control_view
- All attributes that can be set on a
PlayerControlView can also be set on a
PlayerView, and will be propagated to the inflated
PlayerControlView unless the
layout is overridden to specify a custom
exo_controller (see below).
Overriding the layout file
To customize the layout of PlayerView throughout your app, or just for certain configurations,
you can define
exo_player_view.xml layout files in your application
res/layout*directories. These layouts will override the one provided by the ExoPlayer library, and will be
inflated for use by PlayerView. The view identifies and binds its children by looking for the
following ids:
-
exo_content_frame - A frame whose aspect ratio is resized based on the video
or album art of the media being played, and the configured
resize_mode. The video
surface view is inflated into this frame as its first child.
- Type:
AspectRatioFrameLayout
-
exo_shutter - A view that's made visible when video should be hidden. This
view is typically an opaque view that covers the video surface, thereby obscuring it when
visible. Obscuring the surface in this way also helps to prevent flicker at the start of
playback when
surface_type="surface_view".
-
exo_buffering - A view that's made visible when the player is buffering.
This view typically displays a buffering spinner or animation.
-
exo_subtitles - Displays subtitles.
-
exo_artwork - Displays album art.
-
exo_error_message - Displays an error message to the user if playback fails.
-
exo_controller_placeholder - A placeholder that's replaced with the inflated
PlayerControlView. Ignored if an
exo_controller view exists.
-
exo_controller - An already inflated
PlayerControlView. Allows use
of a custom extension of
PlayerControlView. Note that attributes such as
rewind_increment will not be automatically propagated through to this instance. If a view
exists with this id, any
exo_controller_placeholder view will be ignored.
-
exo_overlay - A
FrameLayout positioned on top of the player which
the app can access via
#getOverlayFrameLayout(), provided for convenience.
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 own
exo_player_view.xml is useful to customize the layout of PlayerView
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
player_layout_id attribute on a
PlayerView. This will cause the specified layout to be inflated instead of
exo_player_view.xml for only the instance on which the attribute is set.