Kotlin Android Video PlayerThe 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 classThe 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 ExampleIn this example, we play the video inside the VideoView. activity_main.xmlAdd the following design code in an activity_main.xml file. In this file, we place the VideoView inside the FrameLayout. MainActivity.ktAdd 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. AndroidManifest.xmlAdd the following uses-permission in AndroidManifest.xml file. Output:
Next TopicJSON Parsing using URL
|