Added in API level 1

MediaController


open class MediaController : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ android.widget.MediaController

A view containing controls for a MediaPlayer. Typically contains the buttons like "Play/Pause", "Rewind", "Fast Forward" and a progress slider. It takes care of synchronizing the controls with the state of the MediaPlayer.

The way to use this class is to instantiate it programmatically. The MediaController will create a default set of controls and put them in a window floating above your application. Specifically, the controls will float above the view specified with setAnchorView(). The window will disappear if left idle for three seconds and reappear when the user touches the anchor view.

Functions like show() and hide() have no effect when MediaController is created in an xml layout. MediaController will hide and show the buttons according to these rules:

  • The "previous" and "next" buttons are hidden until setPrevNextListeners() has been called
  • The "previous" and "next" buttons are visible but disabled if setPrevNextListeners() was called with null listeners
  • The "rewind" and "fastforward" buttons are shown unless requested otherwise by using the MediaController(Context, boolean) constructor with the boolean set to false

Summary

Nested classes
abstract

Inherited XML attributes
Inherited constants
Public constructors

MediaController(context: Context!, attrs: AttributeSet!)

MediaController(context: Context!, useFastForward: Boolean)

Public methods
open Boolean

open CharSequence!

open Unit

Remove the controller from the screen.

open Boolean

open Unit

open Boolean

open Boolean

open Unit

Set the view that acts as the anchor for the control view.

open Unit
setEnabled(enabled: Boolean)

open Unit

open Unit

open Unit

Show the controller on screen.

open Unit
show(timeout: Int)

Show the controller on screen.

Inherited functions
Inherited properties

Public constructors

MediaController

Added in API level 1
MediaController(context: Context!)

MediaController

Added in API level 1
MediaController(
    context: Context!,
    attrs: AttributeSet!)

MediaController

Added in API level 1
MediaController(
    context: Context!,
    useFastForward: Boolean)

Public methods

dispatchKeyEvent

Added in API level 1
open fun dispatchKeyEvent(event: KeyEvent!): Boolean
Parameters
event KeyEvent!: The key event to be dispatched.
Return
Boolean True if the event was handled, false otherwise.

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

hide

Added in API level 1
open fun hide(): Unit

Remove the controller from the screen.

isShowing

Added in API level 1
open fun isShowing(): Boolean

onFinishInflate

Added in API level 1
open fun onFinishInflate(): Unit

onTouchEvent

Added in API level 1
open fun onTouchEvent(event: MotionEvent!): Boolean
Parameters
event MotionEvent!: The motion event.
Return
Boolean True if the event was handled, false otherwise.

onTrackballEvent

Added in API level 1
open fun onTrackballEvent(ev: MotionEvent!): Boolean
Parameters
event The motion event.
Return
Boolean True if the event was handled, false otherwise.

setAnchorView

Added in API level 1
open fun setAnchorView(view: View!): Unit

Set the view that acts as the anchor for the control view. This can for example be a VideoView, or your Activity's main view. When VideoView calls this method, it will use the VideoView's parent as the anchor.

Parameters
view View!: The view to which to anchor the controller when it is visible.

setEnabled

Added in API level 1
open fun setEnabled(enabled: Boolean): Unit
Parameters
enabled Boolean: True if this view is enabled, false otherwise.

setMediaPlayer

Added in API level 1
open fun setMediaPlayer(player: MediaController.MediaPlayerControl!): Unit

setPrevNextListeners

Added in API level 1
open fun setPrevNextListeners(
    next: View.OnClickListener!,
    prev: View.OnClickListener!
): Unit

show

Added in API level 1
open fun show(): Unit

Show the controller on screen. It will go away automatically after 3 seconds of inactivity.

show

Added in API level 1
open fun show(timeout: Int): Unit

Show the controller on screen. It will go away automatically after 'timeout' milliseconds of inactivity.

Parameters
timeout Int: The timeout in milliseconds. Use 0 to show the controller until hide() is called.