Javatpoint Logo
Javatpoint Logo

Kotlin Android Video Player

The android.widget.VideoView class is used to play video player in an application. The android.widget.MediaController class provides the playback controls of video player such as play, pause, backward, forward, etc. to control the video player.

Using VideoView and MediaController class we can create a video player.

Method of VideoView class

The android.widget.VideoView class provides several methods to play and control the video player. The commonly used methods of VideoView class are as follows:

Method Description
public void setMediaController(MediaController controller) It sets the media controller to the video view.
public void setVideoURI (Uri uri) It sets the URI of the video file.
public void start() It starts the video view.
public void stopPlayback() It stops the playback.
public void pause() It pauses the playback.
public void suspend() It suspends the playback.
public void resume() It resumes the playback.
public void seekTo(int millis) It seeks to specified time in milliseconds.

Kotlin Android Video Player Example

In this example, we play the video inside the VideoView.


Add the following design code in an activity_main.xml file. In this file, we place the VideoView inside the FrameLayout.


Add the following code in MainActivity.kt class. In this class, we are reading the video file video.mp4 from the sdcard/Movies directory. The path of a video file is placed by creating the instance of Uri class and passed it to VideoView.setVideoURI(Uri). To play the video file call the start() method of VideoView.


Add the following uses-permission in AndroidManifest.xml file.


Kotlin Android Video Player

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA