@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
super.onPlaybackStateChanged(state);
// If there's an ongoing animation, stop it now.
if (mProgressAnimator != null) {
mProgressAnimator.cancel();
mProgressAnimator = null;
}
final int progress = state != null
? (int) state.getPosition()
: 0;
setProgress(progress);
Log.d("nicole", "Set progress to: " + (progress / 1000.0f));
// If the media is playing then the seekbar should follow it, and the easiest
// way to do that is to create a ValueAnimator to update it so the bar reaches
// the end of the media the same time as playback gets there (or close enough).
if (state != null && state.getState() == PlaybackStateCompat.STATE_PLAYING) {
final int timeToEnd = (int) ((getMax() - progress) / state.getPlaybackSpeed());
mProgressAnimator = ValueAnimator.ofInt(progress, getMax())
.setDuration(timeToEnd);
mProgressAnimator.setInterpolator(new LinearInterpolator());
mProgressAnimator.addUpdateListener(this);
mProgressAnimator.start();
}
}
MediaSeekBar.java 文件源码
java
阅读 24
收藏 0
点赞 0
评论 0
项目:mediasession-mediaplayer
作者:
评论列表
文章目录