如何通过订单播放声音顺序?

时间:2014-10-28 15:10:08

标签: java android audio

我需要通过MediaPlayer按顺序播放声音文件顺序。如果我使用setOnCompletionListener,代码会变得更长:

one.start();
one.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
        two.start();
        two.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
            two.start();
            ...three...four...
        }
    });
    }
});

它有更实用的方法吗?

1 个答案:

答案 0 :(得分:1)

仅将播放器的来源更改为下一个媒体。

one.start();
one.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
          one.setDataSource(loopthroughSources); //may be an array or list of files path
          one.start();
        }
    });
    }
});