我有一个切换按钮来播放和停止 .mp3 ,音乐停止了,但是当我取消选中该按钮时,它不会再次启动 mp3。
这是我的代码:
tg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Perform action on clicks
if (tg.isChecked())
{ // Checked - Pause icon visible
// tg.setBackgroundDrawable(d)
try {
mp_tick.stop();
// mp_tick.pause();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else { // Unchecked - Play icon visible
try {
// mp_tick.seekTo(0);
mp_tick.prepare();
mp_tick.start();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
});
我的日志是。
01-30 21:41:00.408: W/System.err(27777): java.io.IOException: Prepare failed.: status=0xFFFFFF8E
01-30 21:41:00.408: W/System.err(27777): at android.media.MediaPlayer.prepare(Native Method)
01-30 21:41:00.408: W/System.err(27777): at com.example.iamgraduate.Questions$2.onClick(Questions.java:101)
01-30 21:41:00.408: W/System.err(27777): at android.view.View.performClick(View.java:3549)
01-30 21:41:00.408: W/System.err(27777): at android.widget.CompoundButton.performClick(CompoundButton.java:100)
01-30 21:41:00.408: W/System.err(27777): at android.view.View$PerformClick.run(View.java:14393)
01-30 21:41:00.408: W/System.err(27777): at android.os.Handler.handleCallback(Handler.java:605)
01-30 21:41:00.408: W/System.err(27777): at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 21:41:00.408: W/System.err(27777): at android.os.Looper.loop(Looper.java:154)
01-30 21:41:00.408: W/System.err(27777): at android.app.ActivityThread.main(ActivityThread.java:4945)
01-30 21:41:00.408: W/System.err(27777): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 21:41:00.418: W/System.err(27777): at java.lang.reflect.Method.invoke(Method.java:511)
01-30 21:41:00.418: W/System.err(27777): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-30 21:41:00.418: W/System.err(27777): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-30 21:41:00.418: W/System.err(27777): at dalvik.system.NativeStart.main(Native Method)