所以我有带有音频文件ID的Ann数组。但这取决于用户那里有多少个ID(他键入“ a”,R.raw.a出现在数组中)。如何使用MediaPlayer依次播放声音。我想我应该使用OnCompletionListener,但我不知道数组中将有多少个声音ID。我应该使用
for(){}
最佳答案
你能做的是
//define a variable to be used as index.
int audioindex = 0;
//Extract the files id into an array
int[] audioFileIds=new int[]{R.raw.as,R.raw.bs};
然后在您的
MediaPlayer
onCompletionListener
中输入以下内容。然后在您的OnCompletionListener中。
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer player) {
// File has ended, play the next one.
FunctionPlayFile(audioFileIds[audioindex]);
audioindex+=1; //increment the index to get the next audiofile
}
});