MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(context, audioUri); mediaPlayer.prepare(); mediaPlayer.setLooping(true); mediaPlayer.start();
MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(context, audioUri); mediaPlayer.prepare(); mediaPlayer.setLooping(false); mediaPlayer.start();In this example, setLooping is set to false so the media file will play only once and not repeat. The android.media package library contains classes that provide access to the audio and video functionality of the Android system. The MediaPlayer class is part of this library and is used for playing media files.