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:
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.