这是我的搜索栏,我不知道mp.getCurrentPosition(); onProgressChanged秒数有时会被3 ... 0:01,0:03,0:05,0:08我不明白为什么? 即时通讯但没有尝试
- 这是我的搜索栏
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, int progress, boolean fromUser) {
mp.getCurrentPosition();
updateProgressBar();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
duration.setText(utils.milliSecondsToTime(mp.getCurrentPosition()));
mHandler.removeCallbacks(mUpdateTimeTask);
updateProgressBar();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.removeCallbacks(mUpdateTimeTask);
int totalDuration = mp.getDuration();
int currentPosition = utils.progressToTimer(seekBar.getProgress(), totalDuration);
mp.seekTo(currentPosition);
updateProgressBar();
}
});
}
- 这是我的转换器
public String milliSecondsToTime(long milliseconds) {
String finalTimerString = "";
String secondString = "";
// Convert total duration into time
int hours = (int) (milliseconds / (1000 * 60 * 60));
int minutes = (int) (milliseconds % (1000 * 60 * 60)) / (1000 * 60);
int seconds = (int) ((milliseconds % (1000 * 60 * 60)) % (1000 * 60) / 1000);
// Add hours if there
if (hours > 0) {
finalTimerString = hours + ":";
}
// Preparing 0 to seconds if it is digit
if (seconds < 10) {
secondString = "0" + seconds;
} else {
secondString = "" + seconds;
}
finalTimerString = finalTimerString + minutes + ":" + secondString;
// return timer string
return finalTimerString;
}