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), or overriding drawables.

    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.
    • 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_REPEAT_TOGGLE_MODES

        @RepeatToggleModes
        public static final @com.google.android.exoplayer2.util.RepeatModeUtil.RepeatToggleModes int DEFAULT_REPEAT_TOGGLE_MODES
        The default repeat toggle modes.
        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.
      • getRepeatToggleModes

        @RepeatToggleModes
        public @com.google.android.exoplayer2.util.RepeatModeUtil.RepeatToggleModes int getRepeatToggleModes()
        Returns which repeat toggle modes are enabled.
        Returns:
        The currently enabled RepeatModeUtil.RepeatToggleModes.
      • setRepeatToggleModes

        public void setRepeatToggleModes​(@RepeatToggleModes
                                         @com.google.android.exoplayer2.util.RepeatModeUtil.RepeatToggleModes int repeatToggleModes)
        Sets which repeat toggle modes are enabled.
        Parameters:
        repeatToggleModes - A set of RepeatModeUtil.RepeatToggleModes.
      • 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.
      • 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