我正在使用音频流应用程序,我们使用搜索栏来显示移动,但是当我们强行改变搜索栏的位置时,它就无法与媒体播放器上播放的歌曲同步。
代码:
seekBarObj
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar seekBar) {
/*
* mHandler.removeCallbacks(mUpdateTimeTask); String[]
* duration =
* lstSongDetails.get(Integer.parseInt(currentPosition
* )).getDuration().split(":"); int intDuration =
* Integer
* .parseInt(duration[0])*60*1000+Integer.parseInt
* (duration[1]);
*
* int currentPosition =
* utils.progressToTimer(seekBar.getProgress(),
* mediaPlayerObj.getDuration());
*
* // forward or backward to certain seconds
* mediaPlayerObj.seekTo(currentPosition);
*/
// update timer progress again
// updateProgressBar();
// mHandler.removeCallbacks(mUpdateTimeTask);
//seekBarObj.setMax(mediaPlayerObj.getDuration());
mHandler.removeCallbacks(mUpdateTimeTask);
//seekBarObj.setProgress(seekBar.getProgress());
long position = (long)mediaPlayerObj.getDuration() * (seekBarObj.getProgress()) / 1000;
mediaPlayerObj.seekTo((int)position);
}
public void onStartTrackingTouch(SeekBar seekBar) {
//mHandler.removeCallbacks(mUpdateTimeTask);
//mediaPlayerObj.seekTo(seekBar.getProgress());
/*long position = (long)mediaPlayerObj.getDuration() * (seekBarObj.getProgress()) / 1000;
mediaPlayerObj.seekTo((int)position);*/
}
public void onProgressChanged(SeekBar seekBar,
int progress, boolean fromUser) {
/*
* mHandler.removeCallbacks(mUpdateTimeTask);
* seekBarObj.setProgress(seekBar.getProgress());
* mediaPlayerObj.seekTo(seekBar.getProgress());
* updateProgressBar();
*/
}
});
private Runnable mUpdateTimeTask = new Runnable() {
public void run() {
long totalDuration = mediaPlayerObj.getDuration();
currentDuration = mediaPlayerObj.getCurrentPosition();
tvSongDurationLeft.setText(""
+ utils.milliSecondsToTimer(currentDuration));
int progress = (int) (utils.getProgressPercentage(currentDuration,
totalDuration));
seekBarObj.setProgress((int) (long) currentDuration);
mHandler.postDelayed(this, 100);
}
};