Added in API level 1

VideoView


open class VideoView : SurfaceView, MediaController.MediaPlayerControl
kotlin.Any
   ↳ android.view.View
   ↳ android.view.SurfaceView
   ↳ android.widget.VideoView

Displays a video file. The VideoView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.

Note: VideoView does not retain its full state when going into the background. In particular, it does not restore the current play state, play position, selected tracks, or any subtitle tracks added via addSubtitleSource(). Applications should save and restore these on their own in android.app.Activity#onSaveInstanceState and android.app.Activity#onRestoreInstanceState.

Also note that the audio session id (from getAudioSessionId) may change from its previously returned value when the VideoView is restored.

By default, VideoView requests audio focus with AudioManager.AUDIOFOCUS_GAIN. Use setAudioFocusRequest(int) to change this behavior.

The default AudioAttributes used during playback have a usage of AudioAttributes.USAGE_MEDIA and a content type of AudioAttributes.CONTENT_TYPE_MOVIE, use setAudioAttributes(android.media.AudioAttributes) to modify them.

Summary

Inherited XML attributes
Inherited constants
Public constructors
VideoView(context: Context!)

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

VideoView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

VideoView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit

Adds an external subtitle source file (from the provided input stream.) Note that a single external subtitle source may contain multiple or no supported tracks in it.

open Boolean

open Boolean

open Boolean

open Unit
draw(canvas: Canvas)

open CharSequence!

open Int

open Int

open Int

open Int

open Boolean

open Boolean
onKeyDown(keyCode: Int, event: KeyEvent!)

open Boolean

open Boolean

open Unit

open Int
resolveAdjustedSize(desiredSize: Int, measureSpec: Int)

open Unit

open Unit
seekTo(msec: Int)

open Unit

Sets the AudioAttributes to be used during the playback of the video.

open Unit

Sets which type of audio focus will be requested during the playback, or configures playback to not request audio focus.

open Unit

open Unit

Register a callback to be invoked when the end of a media file has been reached during playback.

open Unit

Register a callback to be invoked when an error occurs during playback or setup.

open Unit

Register a callback to be invoked when an informational event occurs during playback or setup.

open Unit

Register a callback to be invoked when the media file is loaded and ready to go.

open Unit

Sets video path.

open Unit

Sets video URI.

open Unit
setVideoURI(uri: Uri!, headers: MutableMap<String!, String!>!)

Sets video URI using specific headers.

open Unit

open Unit

open Unit

Protected methods
open Unit

open Unit

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

Inherited functions
Inherited properties

Public constructors

VideoView

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

VideoView

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

VideoView

Added in API level 1
VideoView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

VideoView

Added in API level 21
VideoView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

addSubtitleSource

Added in API level 19
open fun addSubtitleSource(
    is: InputStream!,
    format: MediaFormat!
): Unit

Adds an external subtitle source file (from the provided input stream.) Note that a single external subtitle source may contain multiple or no supported tracks in it. If the source contained at least one track in it, one will receive an MediaPlayer.MEDIA_INFO_METADATA_UPDATE info message. Otherwise, if reading the source takes excessive time, one will receive a MediaPlayer.MEDIA_INFO_SUBTITLE_TIMED_OUT message. If the source contained no supported track (including an empty source file or null input stream), one will receive a android.media.MediaPlayer#MEDIA_INFO_UNSUPPORTED_SUBTITLE message. One can find the total number of available tracks using MediaPlayer.getTrackInfo() to see what additional tracks become available after this method call.

Parameters
is InputStream!: input stream containing the subtitle data. It will be closed by the media framework.
format MediaFormat!: the format of the subtitle track(s). Must contain at least the mime type (MediaFormat.KEY_MIME) and the language (MediaFormat.KEY_LANGUAGE) of the file. If the file itself contains the language information, specify "und" for the language.

canPause

Added in API level 5
open fun canPause(): Boolean

canSeekBackward

Added in API level 5
open fun canSeekBackward(): Boolean

canSeekForward

Added in API level 5
open fun canSeekForward(): Boolean

draw

Added in API level 1
open fun draw(canvas: Canvas): Unit
Parameters
canvas Canvas: The Canvas to which the View is rendered. This value cannot be null.

getAccessibilityClassName

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

getAudioSessionId

Added in API level 18
open fun getAudioSessionId(): Int
Return
Int The audio session, or 0 if there was an error.

getBufferPercentage

Added in API level 1
open fun getBufferPercentage(): Int

getCurrentPosition

Added in API level 1
open fun getCurrentPosition(): Int

getDuration

Added in API level 1
open fun getDuration(): Int

isPlaying

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

onKeyDown

Added in API level 1
open fun onKeyDown(
    keyCode: Int,
    event: KeyEvent!
): Boolean
Parameters
keyCode Int: a key code that represents the button pressed, from android.view.KeyEvent
event KeyEvent!: the KeyEvent object that defines the button action
Return
Boolean If you handled the event, return true. If you want to allow the event to be handled by the next receiver, return false.

onTouchEvent

Added in API level 1
open fun onTouchEvent(ev: MotionEvent!): Boolean
Parameters
event 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.

pause

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

resolveAdjustedSize

Added in API level 1
open fun resolveAdjustedSize(
    desiredSize: Int,
    measureSpec: Int
): Int

resume

Added in API level 8
open fun resume(): Unit

seekTo

Added in API level 1
open fun seekTo(msec: Int): Unit

setAudioAttributes

Added in API level 26
open fun setAudioAttributes(attributes: AudioAttributes): Unit

Sets the AudioAttributes to be used during the playback of the video.

Parameters
attributes AudioAttributes: non-null AudioAttributes.

setAudioFocusRequest

Added in API level 26
open fun setAudioFocusRequest(focusGain: Int): Unit

Sets which type of audio focus will be requested during the playback, or configures playback to not request audio focus. Valid values for focus requests are AudioManager.AUDIOFOCUS_GAIN, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK, and AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE. Or use AudioManager.AUDIOFOCUS_NONE to express that audio focus should not be requested when playback starts. You can for instance use this when playing a silent animation through this class, and you don't want to affect other audio applications playing in the background.

Parameters
focusGain Int: the type of audio focus gain that will be requested, or AudioManager.AUDIOFOCUS_NONE to disable the use audio focus during playback.

setMediaController

Added in API level 1
open fun setMediaController(controller: MediaController!): Unit

setOnCompletionListener

Added in API level 1
open fun setOnCompletionListener(l: MediaPlayer.OnCompletionListener!): Unit

Register a callback to be invoked when the end of a media file has been reached during playback.

Parameters
l MediaPlayer.OnCompletionListener!: The callback that will be run

setOnErrorListener

Added in API level 1
open fun setOnErrorListener(l: MediaPlayer.OnErrorListener!): Unit

Register a callback to be invoked when an error occurs during playback or setup. If no listener is specified, or if the listener returned false, VideoView will inform the user of any errors.

Parameters
l MediaPlayer.OnErrorListener!: The callback that will be run

setOnInfoListener

Added in API level 17
open fun setOnInfoListener(l: MediaPlayer.OnInfoListener!): Unit

Register a callback to be invoked when an informational event occurs during playback or setup.

Parameters
l MediaPlayer.OnInfoListener!: The callback that will be run

setOnPreparedListener

Added in API level 1
open fun setOnPreparedListener(l: MediaPlayer.OnPreparedListener!): Unit

Register a callback to be invoked when the media file is loaded and ready to go.

Parameters
l MediaPlayer.OnPreparedListener!: The callback that will be run

setVideoPath

Added in API level 1
open fun setVideoPath(path: String!): Unit

Sets video path.

Parameters
path String!: the path of the video.

setVideoURI

Added in API level 1
open fun setVideoURI(uri: Uri!): Unit

Sets video URI.

Parameters
uri Uri!: the URI of the video.

setVideoURI

Added in API level 21
open fun setVideoURI(
    uri: Uri!,
    headers: MutableMap<String!, String!>!
): Unit

Sets video URI using specific headers.

Parameters
uri Uri!: the URI of the video.
headers MutableMap<String!, String!>!: the headers for the URI request. Note that the cross domain redirection is allowed by default, but that can be changed with key/value pairs through the headers parameter with "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value to disallow or allow cross domain redirection.

start

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

stopPlayback

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

suspend

Added in API level 8
open fun suspend(): Unit

Protected methods

onAttachedToWindow

Added in API level 1
protected open fun onAttachedToWindow(): Unit

onDetachedFromWindow

Added in API level 1
protected open fun onDetachedFromWindow(): Unit

onLayout

Added in API level 1
protected open fun onLayout(
    changed: Boolean,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit
Parameters
changed Boolean: This is a new size or position for this view
left Int: Left position, relative to parent
top Int: Top position, relative to parent
right Int: Right position, relative to parent
bottom Int: Bottom position, relative to parent

onMeasure

Added in API level 1
protected open fun onMeasure(
    widthMeasureSpec: Int,
    heightMeasureSpec: Int
): Unit
Parameters
widthMeasureSpec Int: horizontal space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.
heightMeasureSpec Int: vertical space requirements as imposed by the parent. The requirements are encoded with android.view.View.MeasureSpec.