当检查切换按钮时,我正在尝试使声音在间隔中播放。单击切换按钮后,我的应用程序不会播放任何声音并崩溃。为什么?
代码:
int bpm;
double timetw;
final Button plus = (Button) findViewById(R.id.tempop);
final Button minus = (Button) findViewById(R.id.tempom);
final TextView curbpm = (TextView) findViewById(R.id.curbpm);
final ToggleButton metronomepp = (ToggleButton) findViewById (R.id.metronomepp);
final MediaPlayer metronome = MediaPlayer.create(this, R.raw.beep);
bpm=60;
timetw=((60/bpm)-0.19)*10000;
curbpm.setText("" + bpm);
Log.i("Metronome1", ""+metronomepp.isChecked());
metronomepp.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
while (metronomepp.isChecked()) {
metronomepp.postDelayed(new Runnable() {
@Override
public void run() {
Log.i("Metronome", "InWhile");
if (metronome.isPlaying()) {metronome.pause();}
metronome.seekTo(0);
metronome.setOnSeekCompleteListener(null);
metronome.start();
metronome.setOnCompletionListener(null)
}
}, (long) (timetw));
}
}
});
按下切换按钮后的 LogCat:
03-14 22:54:17.094: D/dalvikvm(25418): GC_CONCURRENT freed 101K, 3% free 9518K/9735K, paused 3ms+3ms
03-14 22:54:18.019: D/dalvikvm(25418): GC_CONCURRENT freed 5K, 2% free 9923K/10055K, paused 2ms+2ms
03-14 22:54:19.744: D/dalvikvm(25418): GC_CONCURRENT freed 0K, 2% free 10312K/10439K, paused 1ms+1ms
03-14 22:54:23.039: D/dalvikvm(25418): GC_CONCURRENT freed 0K, 2% free 10759K/10887K, paused 1ms+1ms