Class StyledPlayerControlView

  • All Implemented Interfaces:
    Drawable.Callback, AccessibilityEventSource, KeyEvent.Callback, ViewManager, ViewParent

    public class StyledPlayerControlView
    extends FrameLayout
    A view for controlling Player instances.

    A StyledPlayerControlView 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 StyledPlayerControlView 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.
    • show_rewind_button - Whether the rewind button is shown.
    • show_fastforward_button - Whether the fast forward button is shown.
    • show_previous_button - Whether the previous button is shown.
    • show_next_button - Whether the next button is shown.
    • repeat_toggle_modes - A flagged enumeration value specifying which repeat mode toggle options are enabled. Valid values are: none, one, all, or one|all.
    • show_shuffle_button - Whether the shuffle button is shown.
    • show_subtitle_button - Whether the subtitle button is shown.
    • animation_enabled - Whether an animation is used to show and hide the playback controls.
    • time_bar_min_update_interval - Specifies the minimum interval between time bar position updates.
    • controller_layout_id - Specifies the id of the layout to be inflated. See below for more details.
      • Corresponding method: None
      • Default: R.layout.exo_styled_player_control_view
    • All attributes that can be set on DefaultTimeBar can also be set on a StyledPlayerControlView, and will be propagated to the inflated DefaultTimeBar unless the layout is overridden to specify a custom exo_progress (see below).

    Overriding drawables

    The drawables used by StyledPlayerControlView (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_styled_controls_play - The play icon.
    • exo_styled_controls_pause - The pause icon.
    • exo_styled_controls_rewind - The background of rewind icon.
    • exo_styled_controls_fastforward - The background of fast forward icon.
    • exo_styled_controls_previous - The previous icon.
    • exo_styled_controls_next - The next icon.
    • exo_styled_controls_repeat_off - The repeat icon for Player.REPEAT_MODE_OFF.
    • exo_styled_controls_repeat_one - The repeat icon for Player.REPEAT_MODE_ONE.
    • exo_styled_controls_repeat_all - The repeat icon for Player.REPEAT_MODE_ALL.
    • exo_styled_controls_shuffle_off - The shuffle icon when shuffling is disabled.
    • exo_styled_controls_shuffle_on - The shuffle icon when shuffling is enabled.
    • exo_styled_controls_vr - The VR icon.

    Overriding the layout file

    To customize the layout of StyledPlayerControlView throughout your app, or just for certain configurations, you can define exo_styled_player_control_view.xml layout files in your application res/layout* directories. But, in this case, you need to be careful since the default animation implementation expects certain relative positions between children. See also Specifying a custom layout file.

    The layout files in your res/layout* will override the one provided by the ExoPlayer library, and will be inflated for use by StyledPlayerControlView. The view identifies and binds its children by looking for the following ids:

    • exo_play_pause - The play and pause button.
    • exo_rew - The rewind button.
    • exo_rew_with_amount - The rewind button with rewind amount.
      • Type: TextView
      • Note: StyledPlayerControlView will programmatically set the text with the rewind amount in seconds. Ignored if an exo_rew exists. Otherwise, it works as the rewind button.
    • exo_ffwd - The fast forward button.
    • exo_ffwd_with_amount - The fast forward button with fast forward amount.
      • Type: TextView
      • Note: StyledPlayerControlView will programmatically set the text with the fast forward amount in seconds. Ignored if an exo_ffwd exists. Otherwise, it works as the fast forward button.
    • exo_prev - The previous button.
    • exo_next - The next button.
    • exo_repeat_toggle - The repeat toggle button.
      • Type: ImageView
      • Note: StyledPlayerControlView will programmatically set the drawable on the repeat toggle button according to the player's current repeat mode. The drawables used are exo_controls_repeat_off, exo_controls_repeat_one and exo_controls_repeat_all. See the section above for information on overriding these drawables.
    • exo_shuffle - The shuffle button.
      • Type: ImageView
      • Note: StyledPlayerControlView will programmatically set the drawable on the shuffle button according to the player's current repeat mode. The drawables used are exo_controls_shuffle_off and exo_controls_shuffle_on. See the section above for information on overriding these drawables.
    • exo_vr - The VR mode button.
    • exo_subtitle - The subtitle button.
    • exo_fullscreen - The fullscreen button.
    • exo_minimal_fullscreen - The fullscreen button in minimal mode.
    • exo_position - Text view displaying the current playback position.
    • exo_duration - Text view displaying the current media duration.
    • exo_progress_placeholder - A placeholder that's replaced with the inflated DefaultTimeBar. Ignored if an exo_progress view exists.
    • exo_progress - Time bar that's updated during playback and allows seeking. DefaultTimeBar attributes set on the StyledPlayerControlView will not be automatically propagated through to this instance. If a view exists with this id, any exo_progress_placeholder view will be ignored.

    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_styled_player_control_view.xml is useful to customize the layout of StyledPlayerControlView 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 StyledPlayerControlView. This will cause the specified layout to be inflated instead of exo_styled_player_control_view.xml for only the instance on which the attribute is set.

    You need to be careful when you set the controller_layout_id, because the default animation implementation expects certain relative positions between children.

    • Field Detail

      • DEFAULT_SHOW_TIMEOUT_MS

        public static final int DEFAULT_SHOW_TIMEOUT_MS
        The default show timeout, in milliseconds.
        See Also:
        Constant Field Values
      • DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS

        public static final int DEFAULT_TIME_BAR_MIN_UPDATE_INTERVAL_MS
        The default minimum interval between time bar position updates.
        See Also:
        Constant Field Values
      • MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR

        public static final int MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR
        The maximum number of windows that can be shown in a multi-window time bar.
        See Also:
        Constant Field Values
    • Constructor Detail

      • StyledPlayerControlView

        public StyledPlayerControlView​(Context context)
      • StyledPlayerControlView

        public StyledPlayerControlView​(Context context,
                                       @Nullable
                                       AttributeSet attrs)
      • StyledPlayerControlView

        public StyledPlayerControlView​(Context context,
                                       @Nullable
                                       AttributeSet attrs,
                                       int defStyleAttr)
      • StyledPlayerControlView

        public StyledPlayerControlView​(Context context,
                                       @Nullable
                                       AttributeSet attrs,
                                       int defStyleAttr,
                                       @Nullable
                                       AttributeSet playbackAttrs)
    • Method Detail

      • getPlayer

        @Nullable
        public Player getPlayer()
        Returns the Player currently being controlled by this view, or null if no player is set.
      • setPlayer

        public void setPlayer​(@Nullable
                              Player player)
        Sets the Player to control.
        Parameters:
        player - The Player to control, or null to detach the current player. Only players which are accessed on the main thread are supported ( player.getApplicationLooper() == Looper.getMainLooper()).
      • setShowMultiWindowTimeBar

        public void setShowMultiWindowTimeBar​(boolean showMultiWindowTimeBar)
        Sets whether the time bar should show all windows, as opposed to just the current one. If the timeline has a period with unknown duration or more than MAX_WINDOWS_FOR_MULTI_WINDOW_TIME_BAR windows the time bar will fall back to showing a single window.
        Parameters:
        showMultiWindowTimeBar - Whether the time bar should show all windows.
      • setExtraAdGroupMarkers

        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.
        Parameters:
        extraAdGroupTimesMs - The millisecond timestamps of the extra ad markers to show, or null to show no extra ad markers.
        extraPlayedAdGroups - Whether each ad has been played. Must be the same length as extraAdGroupTimesMs, or null if extraAdGroupTimesMs is null.
      • setShowRewindButton

        public void setShowRewindButton​(boolean showRewindButton)
        Sets whether the rewind button is shown.
        Parameters:
        showRewindButton - Whether the rewind button is shown.
      • setShowFastForwardButton

        public void setShowFastForwardButton​(boolean showFastForwardButton)
        Sets whether the fast forward button is shown.
        Parameters:
        showFastForwardButton - Whether the fast forward button is shown.
      • setShowPreviousButton

        public void setShowPreviousButton​(boolean showPreviousButton)
        Sets whether the previous button is shown.
        Parameters:
        showPreviousButton - Whether the previous button is shown.
      • setShowNextButton

        public void setShowNextButton​(boolean showNextButton)
        Sets whether the next button is shown.
        Parameters:
        showNextButton - Whether the next button is shown.
      • getShowTimeoutMs

        public int getShowTimeoutMs()
        Returns the playback controls timeout. The playback controls are automatically hidden after this duration of time has elapsed without user input.
        Returns:
        The duration in milliseconds. A non-positive value indicates that the controls will remain visible indefinitely.
      • setShowTimeoutMs

        public void setShowTimeoutMs​(int showTimeoutMs)
        Sets the playback controls timeout. The playback controls are automatically hidden after this duration of time has elapsed without user input.
        Parameters:
        showTimeoutMs - The duration in milliseconds. A non-positive value will cause the controls to remain visible indefinitely.
      • getShowShuffleButton

        public boolean getShowShuffleButton()
        Returns whether the shuffle button is shown.
      • setShowShuffleButton

        public void setShowShuffleButton​(boolean showShuffleButton)
        Sets whether the shuffle button is shown.
        Parameters:
        showShuffleButton - Whether the shuffle button is shown.
      • getShowSubtitleButton

        public boolean getShowSubtitleButton()
        Returns whether the subtitle button is shown.
      • setShowSubtitleButton

        public void setShowSubtitleButton​(boolean showSubtitleButton)
        Sets whether the subtitle button is shown.
        Parameters:
        showSubtitleButton - Whether the subtitle button is shown.
      • getShowVrButton

        public boolean getShowVrButton()
        Returns whether the VR button is shown.
      • setShowVrButton

        public void setShowVrButton​(boolean showVrButton)
        Sets whether the VR button is shown.
        Parameters:
        showVrButton - Whether the VR button is shown.
      • setVrButtonListener

        public void setVrButtonListener​(@Nullable
                                        View.OnClickListener onClickListener)
        Sets listener for the VR button.
        Parameters:
        onClickListener - Listener for the VR button, or null to clear the listener.
      • setAnimationEnabled

        public void setAnimationEnabled​(boolean animationEnabled)
        Sets whether an animation is used to show and hide the playback controls.
        Parameters:
        animationEnabled - Whether an animation is applied to show and hide playback controls.
      • isAnimationEnabled

        public boolean isAnimationEnabled()
        Returns whether an animation is used to show and hide the playback controls.
      • setTimeBarMinUpdateInterval

        public void setTimeBarMinUpdateInterval​(int minUpdateIntervalMs)
        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 - The minimum interval between time bar position updates, in milliseconds.
      • setOnFullScreenModeChangedListener

        public void setOnFullScreenModeChangedListener​(@Nullable
                                                       StyledPlayerControlView.OnFullScreenModeChangedListener listener)
        Sets a listener to be called when the fullscreen mode should be changed. A non-null listener needs to be set in order to display the fullscreen button.
        Parameters:
        listener - The listener to be called. A value of null removes any existing listener and hides the fullscreen button.
      • show

        public void show()
        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.
      • hide

        public void hide()
        Hides the controller.
      • hideImmediately

        public void hideImmediately()
        Hides the controller without any animation.
      • isFullyVisible

        public boolean isFullyVisible()
        Returns whether the controller is fully visible, which means all UI controls are visible.
      • isVisible

        public boolean isVisible()
        Returns whether the controller is currently visible.
      • dispatchMediaKeyEvent

        public boolean dispatchMediaKeyEvent​(KeyEvent event)
        Called to process media key events. Any KeyEvent can be passed but only media key events will be handled.
        Parameters:
        event - A key event.
        Returns:
        Whether the key event was handled.
      • onLayout

        protected void onLayout​(boolean changed,
                                int left,
                                int top,
                                int right,
                                int bottom)
        Overrides:
        onLayout in class FrameLayout