我希望我的程序连续播放特定的音频剪辑而没有任何启动延迟,因为我创建了一个程序,但它没有像我提到的那样工作,所以请有人帮我解决这个问题
代码
import android.app.Activity;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener {
LocalService mService;
boolean mBound = false;
Button btn1;
Button btn2;
MediaPlayer yourStereo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1=(Button)findViewById(R.id.a_button);
btn2=(Button)findViewById(R.id.b_button);
btn1.setOnClickListener(this);
}
@Override
public void onClick(View arg0) {
// play music here
btn1.setVisibility(Button.GONE);
btn2.setVisibility(Button.VISIBLE);
// TODO Auto-generated method stub
yourStereo = MediaPlayer.create(this, R.raw.pl);
yourStereo.start();
yourStereo.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
yourStereo.start();
}
});
// pause music here
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
yourStereo.stop();
btn2.setVisibility(Button.GONE);
btn1.setVisibility(Button.VISIBLE);
}
});
}
}