MediaPlayer play songs serially

2019-08-29 10:26发布

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

1条回答
来,给爷笑一个
2楼-- · 2019-08-29 10:56

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

        });
查看更多
登录 后发表回答