0
確定我的切換按鈕工作正常,但我的MP3沒有開始後,其停止。這裏是我的代碼,請告訴我適當的方式停止並重新開始MP3音效。這裏是我的代碼和調試日誌。播放和停止或暫停MP3
public void toggleclick(View v) throws IllegalStateException, IOException{
if(tg.isChecked())
{
if(mp_tick.isPlaying())
mp_tick.stop();
//mp_tick.release();
Toast.makeText(this, "ON", Toast.LENGTH_SHORT).show();
}
else
mp_tick.prepare();
mp_tick.start();
// mp_tick.start();
Toast.makeText(this, "OFF", Toast.LENGTH_SHORT).show();
}
這裏是我的日誌:
02-07 16:21:43.651: D/MediaPlayer(24554): start() in
02-07 16:21:43.651: E/MediaPlayer(24554): start called in state 0
02-07 16:21:43.651: E/MediaPlayer(24554): error (-38, 0)
02-07 16:21:43.651: D/MediaPlayer(24554): start() out
02-07 16:21:44.652: D/MediaPlayer(24554): start() in
02-07 16:21:44.652: E/MediaPlayer(24554): start called in state 0
02-07 16:21:44.652: E/MediaPlayer(24554): error (-38, 0)
02-07 16:21:44.652: D/MediaPlayer(24554): start() out
當您創建MediaPlayer時添加代碼。 – Xry 2015-02-07 12:21:20