我需要通过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...
}
});
}
});
它有更实用的方法吗?
答案 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();
}
});
}
});