Class PlayerControlView

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

    @Deprecated
    public class PlayerControlView
    extends FrameLayout
    Deprecated.
    com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.
    A view for controlling Player instances.

    A PlayerControlView 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 PlayerControlView 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.
    • 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_player_control_view
    • All attributes that can be set on DefaultTimeBar can also be set on a PlayerControlView, 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 PlayerControlView (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_controls_play - The play icon.
    • exo_controls_pause - The pause icon.
    • exo_controls_rewind - The rewind icon.
    • exo_controls_fastforward - The fast forward icon.
    • exo_controls_previous - The previous icon.
    • exo_controls_next - The next icon.
    • exo_controls_repeat_off - The repeat icon for Player.REPEAT_MODE_OFF.
    • exo_controls_repeat_one - The repeat icon for Player.REPEAT_MODE_ONE.
    • exo_controls_repeat_all - The repeat icon for Player.REPEAT_MODE_ALL.
    • exo_controls_shuffle_off - The shuffle icon when shuffling is disabled.
    • exo_controls_shuffle_on - The shuffle icon when shuffling is enabled.
    • exo_controls_vr - The VR icon.

    Overriding the layout file

    To customize the layout of PlayerControlView throughout your app, or just for certain configurations, you can define exo_player_control_view.xml layout files in your application res/layout* directories. These layouts will override the one provided by the library, and will be inflated for use by PlayerControlView. The view identifies and binds its children by looking for the following ids:
    • exo_play - The play button.
    • exo_pause - The pause button.
    • exo_rew - The rewind button.
    • exo_ffwd - The fast forward button.
    • exo_prev - The previous button.
    • exo_next - The next button.
    • exo_repeat_toggle - The repeat toggle button.
      • Type: ImageView
      • Note: PlayerControlView 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: PlayerControlView 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_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 PlayerControlView 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_player_control_view.xml is useful to customize the layout of PlayerControlView 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 PlayerControlView. This will cause the specified layout to be inflated instead of exo_player_control_view.xml for only the instance on which the attribute is set.
    • Field Detail

      • DEFAULT_SHOW_TIMEOUT_MS

        public static final int DEFAULT_SHOW_TIMEOUT_MS
        Deprecated.
        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
        Deprecated.
        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
        Deprecated.
        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
        Deprecated.
        The maximum number of windows that can be shown in a multi-window time bar.
        See Also:
        Constant Field Values
    • Constructor Detail

      • PlayerControlView

        public PlayerControlView​(Context context)
        Deprecated.
      • PlayerControlView

        public PlayerControlView​(Context context,
                                 @Nullable
                                 AttributeSet attrs)
        Deprecated.
      • PlayerControlView

        public PlayerControlView​(Context context,
                                 @Nullable
                                 AttributeSet attrs,
                                 int defStyleAttr)
        Deprecated.
      • PlayerControlView

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

      • getPlayer

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

        public void setPlayer​(@Nullable
                              Player player)
        Deprecated.
        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)
        Deprecated.
        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)
        Deprecated.
        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)
        Deprecated.
        Sets whether the rewind button is shown.
        Parameters:
        showRewindButton - Whether the rewind button is shown.
      • setShowFastForwardButton

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

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

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

        public int getShowTimeoutMs()
        Deprecated.
        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)
        Deprecated.
        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()
        Deprecated.
        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)
        Deprecated.
        Sets which repeat toggle modes are enabled.
        Parameters:
        repeatToggleModes - A set of RepeatModeUtil.RepeatToggleModes.
      • getShowShuffleButton

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

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

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

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

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

        public void setTimeBarMinUpdateInterval​(int minUpdateIntervalMs)
        Deprecated.
        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()
        Deprecated.
        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()
        Deprecated.
        Hides the controller.
      • isVisible

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

        public boolean dispatchMediaKeyEvent​(KeyEvent event)
        Deprecated.
        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.