[英]How to play list of mp3 files from raw folder in a loop
I have many Sound Files (.MP3) in res/raw
folder. 我在
res/raw
文件夹中有很多声音文件(.MP3)。 I want to play each file one by one. 我想一个一个地播放每个文件。
Here is my code 这是我的代码
int [] resID ={ R.raw.s1,R.raw.s2,R.raw.s3,R.raw.s4,R.raw.s5};
ArrayList<Integer> indexForMusic;
..........................
..........................
// on click of play button
public void playMusic(View v)
{
for(int i:indexForMusic)
{
MediaPlayer mediaPlayer=MediaPlayer.create(this,resID[i]);
mediaPlayer.start();
try
{
wait(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
but the problem is that all MP3 files are getting played simultanously, and there is no delay beteew the playing of files.. 但是问题在于所有MP3文件都可以同时播放,而且播放文件没有延迟。
Please tell me how can i play music one after the other? 请告诉我我该如何依次播放音乐? putting wait() inside for loop is throwing an exception.
将wait()放入for循环会引发异常。
Try thread, something like following 尝试线程,如下所示
Thread T=new Thread(new runnable(){
public void run(){
MediaPlayer mediaPlayer=MediaPlayer.create(this,resID[i]);
mediaPlayer.start();
try
{
sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
}
}
);
T.start();
simultaneously*, or try CountDownTimer 同时*,或尝试CountDownTimer
new CountDownTimer(1000, 100)
{
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
mediaPlayer.start();
}
}.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.