Kotlin Android Media Player
MediaPlayer is a class that is used to control the playback of audio/video files and streams.
The android.media.MediaPlayer class is used to control the audio or video files. It accesses the built-in media player services such as playing audio, video, etc. To use the MediaPlayer class, we have to call the create the instance of it by calling the create() method of this class.
Methods of MediaPlayer class
There are several methods of MediaPlayer class available. Some of them are as follows:
Example of Android MediaPlayer with SeekBar
In this example, we will create a Media Player with playback control functionality such as play, pause, and stop. We also integrate the SeekBar to show the progress level of the media player.
In the activity_main.xml layout file, we add the Buttons to control media playback, TextView to display the time duration of song and SeekBar to show the progress level of the media file.
The instance of MediaPlayer class is created using the MediaPlayer.create() method. In this example, we are reading the media file from the raw directory. The MediaPlayer.start() method starts playing media file, MediaPlayer.pause() method pause media and Media.stop() method stops playing media file.