我已经实现了搜索者和媒体播放器但是应用程序在onPause()事件期间崩溃了,我的代码部分导致了问题:
updateSeekBar = new Thread( ){
@Override
public void run() {
int totalduration = mediaPlayer.getDuration();
int currentPosition = 0;
while(currentPosition < totalduration && !isOnPause){
try {
Message message = new Message();
message.what = mediaPlayer.getCurrentPosition();
handler.sendMessage(message);
sleep(500);
currentPosition = mediaPlayer.getCurrentPosition();
positionBar.setProgress(currentPosition);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
错误:
04-16 19:54:11.298 24488-24527/com.xxxxxx.xxxxxxE/AndroidRuntime: FATAL EXCEPTION: Thread-4
Process: com.xxxxxxx.xxxxx, PID: 24488
java.lang.IllegalStateException
at android.media.MediaPlayer.getCurrentPosition(Native Method)
at com.soleofficiel.happykiosk.NewOneMusicPlayer$1.run(NewOneMusicPlayer.java:79)