本文介绍了的MediaPlayer播放歌曲串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要打比方说,连续10首歌曲(1-10)。一个是发挥和完成后,下一个开始,等我心目中是:

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

推荐答案

您可以使用mp.setOnCompletionListener为当歌曲读完。见下面的例子:

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

        });

这篇关于的MediaPlayer播放歌曲串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 04:25