Question

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

Was it helpful?

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..
        }

        });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top