这段代码可以完美地播放精美的歌曲,但有些时间随机转到下一首歌会手动崩溃应用程序.随机发生
updateSeekBar = new Thread() {
@Override
public void run() {
int runtime = mediaPlayer.getDuration();
int currentPosition = 0;
while (currentPosition < runtime) {
try {
sleep(500);
currentPosition = mediaPlayer.getCurrentPosition();//This is where the app crash
if (seekBar != null) {
seekBar.setProgress(currentPosition);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
崩溃报告
06-10 22:08:53.160 15351-15560/skydeveloper.me.musicx2 E/AndroidRuntime: FATAL EXCEPTION: Thread-6875
Process: skydeveloper.me.musicx2, PID: 15351
java.lang.IllegalStateException
at android.media.MediaPlayer.getCurrentPosition(Native Method)
at skydeveloper.me.musicx2.Player$1.run(Player.java:104)
版权声明:本文为weixin_40001025原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。