Search code examples
androideclipsemedia-player

MediaPlayer play songs serially


I need to play let's say 10 songs (1-10) serially. After one is played and finished, the next one starts, etc. What I have in mind is:

For (int i=0; i<10; i++) {
    mp = new MediaPlayer();
    mp.setDataSource(/* something given i */);
    mp.prepare();
    mp.start();
}

But won't that cause just one song to be played only? What could I do to make a row of them? Thanks a lot


Solution

  • you can use mp.setOnCompletionListener for reading when a song is finished. See example below:

            mp.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                //code for starting next song..
            }
    
            });