動きを示すためにシークバーを使用しているオーディオ ストリーミング アプリに取り組んでいますが、シーク バーの位置を強制的に変更すると、メディア プレーヤーで再生中の曲と同期できません。
コード:
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);
}
};