1
我有一個按鈕,播放隨機聲音片段後跟隨另一個然後另一個媒體播放器,但按多次按鈕後(15-20次)所有音頻只是停下來。我在播放最後一個音頻剪輯後釋放媒體播放器,所以我沒有看到這是原因。任何指針?Media Player在播放幾次後停止播放
public class Main extends Activity {
MediaPlayer mp;
Button generate;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
generate = (Button) findViewById(R.id.sound);
}
public void youSir (View view)
{
generate.setVisibility(View.INVISIBLE);
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(3) + 1;
switch (randomInt){
case 1: mp = MediaPlayer.create(this, R.raw.beg); mp.start();
break;
case 2: mp = MediaPlayer.create(this, R.raw.begone); mp.start();
break;
case 3: mp = MediaPlayer.create(this, R.raw.begtwo); mp.start();
break;
}
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
audioTwo();
}
});
}
protected void audioTwo() {
// TODO Auto-generated method stub
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(3) + 1;
switch (randomInt){
case 1: mp = MediaPlayer.create(this, R.raw.start); mp.start();
break;
case 2: mp = MediaPlayer.create(this, R.raw.end); mp.start();
break;
case 3: mp = MediaPlayer.create(this, R.raw.mid); mp.start();
break;
}
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
audioThree();
}
});
}
protected void audioThree() {
// TODO Auto-generated method stub
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(3) + 1;
switch (randomInt){
case 1: mp = MediaPlayer.create(this, R.raw.three); mp.start();
break;
case 2: mp = MediaPlayer.create(this, R.raw.two); mp.start();
break;
case 3: mp = MediaPlayer.create(this, R.raw.one); mp.start();
break;
mp.setOnCompletionListener(new OnCompletionListener(){
// @Override
public void onCompletion(MediaPlayer arg0) {
mp.stop();
mp.release();
generate.setVisibility(View.VISIBLE);
}
});
}