MediaControlView

Added in 1.0.0
Deprecated in 1.3.0

public class MediaControlView extends ViewGroup


A View that contains the controls for androidx.media2.session.MediaController or . It provides a wide range of buttons that serve the following functions: play/pause, rewind/fast-forward, skip to next/previous, select subtitle track, enter/exit full screen mode, select audio track, and adjust playback speed.

For simple use cases not requiring communication with , apps need to create a (e.g. androidx.media2.player.MediaPlayer) and set it to this view by calling setPlayer. For more advanced use cases that require (e.g. handling media key events, integrating with other androidx.media2.session.MediaSession apps as Assistant), apps need to create a attached to the and set it to this view by calling setMediaController.

The easiest way to use a MediaControlView is by creating a VideoView, which internally creates a MediaControlView instance and handles all the commands from buttons inside MediaControlView. It is also possible to create a MediaControlView programmatically and add it to a custom video view. For more information, refer to VideoView.

By default, each button in the MediaControlView is visible only when its corresponding is included in the active . For more details, refer to setAllowedCommands.

UI transitions

The UI of an app can be in one of three modes:
  • In full mode all the views, such as progress bar, title, transport controls, and other icons are visible.
  • In progress-bar only mode the progress bar is the only visible element. The title, transport controls, and other icons are hidden.
  • In None mode all the views are hidden.
When the UI mode changes, MediaControlView animates the transition. The animation does not start immediately, there is a default delay interval of 2000ms before the animation begins. You can change this interval by calling setMediaControlView.

User actions can change the scheduled transition during the delay interval according to the following logic:

  1. In Full mode
    • If a touch/trackball event is received during the interval, the UI changes to None mode.
    • If no touch/trackball event is received during the interval, the UI changes to progress-bar only mode.
  2. In Progress-bar only mode
    • If a touch/trackball event is received, the UI changes to Full mode.
    • If no touch/trackball event is received, the UI changes to None mode.
  3. In None mode, if a touch/trackball event is received, the UI changes to Full mode.
All touch/trackballs events are ignored while the system is animating the change between modes.

Customization

The following customizations are supported:

Displaying metadata

MediaControlView supports displaying metadata by calling setMetadata. Metadata display is different for two different media types: video (with or without sound) and audio(sound only, no video)

The following table shows the metadata displayed on VideoView and the default values assigned if the keys are not set:

Key Default
METADATA_KEY_TITLE mcv2_music_title_unknown_text
METADATA_KEY_ARTIST mcv2_music_artist_unknown_text
METADATA_KEY_ALBUM_ART media2_widget_ic_default_album_image

For video media, METADATA_KEY_TITLE metadata is supported. If the value is not set, the following default value will be shown: mcv2_non_music_title_unknown_text

Summary

Nested types

This interface is deprecated.

androidx.media2 is deprecated.

Public constructors

MediaControlView(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

Public methods

CharSequence
boolean
boolean
void
@RequiresApi(value = 24)
onVisibilityAggregated(boolean isVisible)
void

Requests focus for the play/pause button.

void

Sets androidx.media2.session.MediaController to control playback with this view.

void

Sets a listener to be called when the fullscreen mode should be changed.

void

Sets androidx.media2.common.SessionPlayer to control playback with this view.

Protected methods

void
void
void
onLayout(boolean changed, int left, int top, int right, int bottom)
void
onMeasure(int widthMeasureSpec, int heightMeasureSpec)
void
onVisibilityChanged(@NonNull View view, int visibility)
void
onWindowVisibilityChanged(int visibility)

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
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 float
static final float
static final float
static final float
static final float
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.view.View
void
void
void
ViewPropertyAnimator
void

This method is deprecated.

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
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<Integer