Runnable不会更新音乐播放器中的SeekBar

时间:2016-09-26 17:51:31

标签: android runnable android-seekbar

playb.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            player = MediaPlayer.create(MainActivity.this, R.raw.song);
            player.start();
            playb.setClickable(false);
            seeksong.setMax(player.getDuration());
            new Thread(new SeekHandler()).start();
          }
    });
 SeekHandler extends MainActivity implements Runnable{
@Override
public void run() {
    while (player != null && player.getCurrentPosition() < player.getDuration()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            return;
        } catch (Exception e) {
            return;
        }
        seeksong.setProgress(player.getCurrentPosition());
    }
}

SeekBar没有更新到当前歌曲位置。请告诉我这样做的正确方法。如果有其他方法可供选择

0 个答案:

没有答案