Join us on the livestream at Android Dev Summit on 7-8 November 2018, starting at 10AM PDT!

MediaControlView2

public class MediaControlView2
extends ViewGroup

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ androidx.media.widget.MediaControlView2


A View that contains the controls for MediaPlayer. 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, adjust video quality, select audio track, mute/unmute, and adjust playback speed.

MediaControlView2 can be initialized in two different ways: 1) When initializing VideoView2 a default MediaControlView2 is created. 2) Initialize MediaControlView2 programmatically and add it to a ViewGroup instance. In the first option, VideoView2 automatically connects MediaControlView2 to MediaController, which is necessary to communicate with MediaSession. In the second option, however, the developer needs to manually retrieve a MediaController instance from MediaSession and set it to MediaControlView2.

There is no separate method that handles the show/hide behavior for MediaControlView2. Instead, one can directly change the visibility of this view by calling View.setVisibility(int). The values supported are View.VISIBLE and View.GONE.

In addition, the following customizations are supported: 1) Set focus to the play/pause button by calling requestPlayButtonFocus(). 2) Set full screen mode

Summary

Nested classes

interface MediaControlView2.OnFullScreenListener

Interface definition of a callback to be invoked to inform the fullscreen mode is changed. 

Inherited constants

Inherited fields

Public constructors

MediaControlView2(Context context)
MediaControlView2(Context context, AttributeSet attrs)
MediaControlView2(Context context, AttributeSet attrs, int defStyleAttr)

Public methods

boolean checkLayoutParams(ViewGroup.LayoutParams p)
ViewGroup.LayoutParams generateDefaultLayoutParams()
ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams lp)
ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs)
CharSequence getAccessibilityClassName()
void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
boolean onTouchEvent(MotionEvent ev)
boolean onTrackballEvent(MotionEvent ev)
void onVisibilityAggregated(boolean isVisible)
void requestPlayButtonFocus()

Requests focus for the play/pause button.

void setEnabled(boolean enabled)
void setMediaSessionToken2(SessionToken2 token)

Sets MediaSession2 token to control corresponding MediaSession2.

void setOnFullScreenListener(MediaControlView2.OnFullScreenListener l)

Registers a callback to be invoked when the fullscreen mode should be changed.

boolean shouldDelayChildPressedState()

Protected methods

void onLayout(boolean changed, int left, int top, int right, int bottom)

Inherited methods

Public constructors

MediaControlView2

public MediaControlView2 (Context context)

Parameters
context Context

MediaControlView2

public MediaControlView2 (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

MediaControlView2

public MediaControlView2 (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context

attrs AttributeSet

defStyleAttr int

Public methods

checkLayoutParams

public boolean checkLayoutParams (ViewGroup.LayoutParams p)

Parameters
p ViewGroup.LayoutParams

Returns
boolean

generateDefaultLayoutParams

public ViewGroup.LayoutParams generateDefaultLayoutParams ()

Returns
ViewGroup.LayoutParams

generateLayoutParams

public ViewGroup.LayoutParams generateLayoutParams (ViewGroup.LayoutParams lp)

Parameters
lp ViewGroup.LayoutParams

Returns
ViewGroup.LayoutParams

generateLayoutParams

public ViewGroup.LayoutParams generateLayoutParams (AttributeSet attrs)

Parameters
attrs AttributeSet

Returns
ViewGroup.LayoutParams

getAccessibilityClassName

public CharSequence getAccessibilityClassName ()

Returns
CharSequence

onMeasure

public void onMeasure (int widthMeasureSpec, 
                int heightMeasureSpec)

Parameters
widthMeasureSpec int

heightMeasureSpec int

onTouchEvent

public boolean onTouchEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

onTrackballEvent

public boolean onTrackballEvent (MotionEvent ev)

Parameters
ev MotionEvent

Returns
boolean

onVisibilityAggregated

public void onVisibilityAggregated (boolean isVisible)

Parameters
isVisible boolean

requestPlayButtonFocus

public void requestPlayButtonFocus ()

Requests focus for the play/pause button.

setEnabled

public void setEnabled (boolean enabled)

Parameters
enabled boolean

setMediaSessionToken2

public void setMediaSessionToken2 (SessionToken2 token)

Sets MediaSession2 token to control corresponding MediaSession2. It makes it possible to send and receive data between MediaControlView2 and VideoView2.

Parameters
token SessionToken2

setOnFullScreenListener

public void setOnFullScreenListener (MediaControlView2.OnFullScreenListener l)

Registers a callback to be invoked when the fullscreen mode should be changed. This needs to be implemented in order to display the fullscreen button.

Parameters
l MediaControlView2.OnFullScreenListener: The callback that will be run

shouldDelayChildPressedState

public boolean shouldDelayChildPressedState ()

Returns
boolean

Protected methods

onLayout

protected void onLayout (boolean changed, 
                int left, 
                int top, 
                int right, 
                int bottom)

Parameters
changed boolean

left int

top int

right int

bottom int