Seekbar不会更新

时间:2014-02-21 17:16:09

标签: android android-mediaplayer seekbar

我想播放音乐,所以我用搜索器来显示进度,一切都很好,直到我按下暂停按钮,搜索栏停止但是当我按下播放按钮时,搜索栏不移动,我想出来是因为getcurrentposition()方法,暂停后不更新,下面是我的代码,它有什么问题?

@Override
        public void onClick(View v) {
            try {
                if (isPlaying) {
                    buttonPlayPause.setImageResource(R.drawable.play);
                    mediaPlayer.pause();
                    isPlaying = false;
                } else {
                    buttonPlayPause.setImageResource(R.drawable.pause);
                    isPlaying = true;
                    mediaPlayer.start();
                    primarySeekBarProgressUpdater();
                }
            } catch (Exception e) {
                onDestroy();
            }
        }
    }); 


 private void primarySeekBarProgressUpdater() {
    try {
        seekBarProgress
                .setProgress((int) (((float) mediaPlayer
                        .getCurrentPosition() / mediaFileLengthInMilliseconds) * 100));
        if (mediaPlayer.isPlaying()) {
            Runnable notification = new Runnable() {
                public void run() {
                    primarySeekBarProgressUpdater();
                }
            };
            handler.postDelayed(notification, 1000);
        }
    } catch (Exception e) {
        onDestroy();
    }
}

0 个答案:

没有答案