如何使一个按钮每次被按下时随机播放一列声音?

时间:2018-07-30 18:56:11

标签: java android

我知道如何使1个按钮播放1个音频文件,但是如何使1个按钮随机播放多个声音文件?

1 个答案:

答案 0 :(得分:0)

将所有音频的uri添加到ArrayList中,然后从中选择随机uri作为-

ArrayList<Uri> list = new ArrayList();
list.add(audio1Uri1);
list.add(audio1Uri2);
list.add(audio1Uri3);

Collections.shuffle(list);

System.out.println("" + list);
//This will give you random songs everytime. Pass the element one by one to media player. And play the next song by checking if the previous one has finished