Kotlin Android Media PlayerMediaPlayer 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 classThere are several methods of MediaPlayer class available. Some of them are as follows:
Example of Android MediaPlayer with SeekBarIn 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. activity_main.xmlIn 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. MianActivity.ktThe 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. Output: Next TopicAndroid Video Player |