Search code examples
androidmedia-player

How to Make the Music Loop After the Music Ends Android


I just wanted the music in my activity to play endlessly (i.e. when my 38-second music ends, i wanted to play it again and again until the user leaves the page). By the way, i am using MediaPlayer.

 ourSound = MediaPlayer.create(NewKFCActivity.this, R.raw.start);
 ourSound.start();

Cheers!


Solution

  • You can call MediaPlayer#setLooping(boolean):

    ourSound = MediaPlayer.create(NewKFCActivity.this, R.raw.start);
    ourSound.setLooping(true);
    ourSound.start();