这是我的代码,我几乎可以肯定问题是与while循环。音乐播放器的进度条不工作和崩溃
public void start(View view) {
int currentPosition = 0;
player = MediaPlayer.create(this, R.raw.sound);
player.start();
int total = player.getDuration();
progressBar.setProgress(0);
progressBar.setMax(player.getDuration());
while (player != null && currentPosition < total) {
// try {
// Thread.sleep(500);
currentPosition = player.getCurrentPosition();
// } catch (InterruptedException e) {
// return;
// } catch (Exception e) {
// return;
// }
progressBar.setProgress(currentPosition);
}
}
public void stop(View view) {
player.stop();
}
是否我有睡眠间隔我的结果是相同的;声音开始播放,但我无法停止它,并且进度条不动。 我将不胜感激
是什么'getCurrentPosition()'做什么?它实际上是否返回一个值?你的意思是进度条不动?有没有用户界面? – lux