我试图在“res/raw”文件夹之后在android中播放声音。但它只播放声音数组中的第一个声音。还有其他方法吗?
raw文件夹中有三个声音文件
1.aa.ogg 2.ma.ogg 3.ar.ogg
package com.protonray.calculatorplus;
import java.util.List;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
public class LayoutNew extends Activity{
int count=0;
int[] sounds={R.raw.aa,R.raw.ma,R.raw.ar };
MediaPlayer mp=new MediaPlayer();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_new);
Button play=(Button) findViewById(R.id.play);
play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
count =0 ;
//Play the Frist sound
mp =MediaPlayer.create(LayoutNew.this,sounds[count]);
mp.start();
count =1 ;
}
});
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
if(count<3){
mp.stop();
//Play next sound
mp =MediaPlayer.create(LayoutNew.this,sounds[count]);
mp.start();
count++;
}
}
});
}
}