MediaPlayer play songs serially

99封情书 提交于 2019-12-13 05:09:16

问题


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:


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

        });


来源:https://stackoverflow.com/questions/23648088/mediaplayer-play-songs-serially

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!