我想播放声音。第一次可以正常播放,但是如果我停止它并想重新开始,什么都不会发生...有任何想法吗?
final MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.sex);
ImageButton andvib = (ImageButton)findViewById(R.id.vib_toggle);
final AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
andvib.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
am.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);
Vibrator vibr = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
vibr.cancel();
if(vibrating==false) {
if(style == 0)
vibr.vibrate(durat, 0);
if(style == 1){
vibr.vibrate(staccato, 0);
}
if(style == 2){
vibr.vibrate(wild, 0);
}
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mp.start();
mp.setLooping(true);
vibrating = true;
}
else {
vibrating = false;
mp.stop();
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
vibr.cancel();
}
}
});