@Override public void updateProgress(PlaybackStateCompat playbackState, long duration) { if (playbackState == null) { return; } long currentPosition = playbackState.getPosition(); if (playbackState.getState() != PlaybackStateCompat.STATE_PAUSED) { // Calculate the elapsed time between the last position update and now and unless // paused, we can assume (delta * speed) + current position is approximately the // latest position. This ensure that we do not repeatedly call the getPlaybackState() // on MediaControllerCompat. long timeDelta = SystemClock.elapsedRealtime() - playbackState.getLastPositionUpdateTime(); currentPosition += (int) timeDelta * playbackState.getPlaybackSpeed(); } mProgressBar .setProgress((int) ((float) currentPosition / duration * 10000)); mPlayPauseButton.setProgress((float) currentPosition / duration * 1000); mCurrentTimeTextView.setText(ViewUtils.durationToString(currentPosition)); } });
@Override public void updateProgress(PlaybackStateCompat playbackState, long duration) { if (playbackState != null && mTomahawkListAdapter != null && mTomahawkListAdapter.getProgressBar() != null) { long currentPosition = playbackState.getPosition(); if (playbackState.getState() != PlaybackStateCompat.STATE_PAUSED) { // Calculate the elapsed time between the last position update and now // and unless paused, we can assume (delta * speed) + current position // is approximately the latest position. This ensure that we do not // repeatedly call the getPlaybackState() on MediaControllerCompat. long timeDelta = SystemClock.elapsedRealtime() - playbackState.getLastPositionUpdateTime(); currentPosition += (int) timeDelta * playbackState.getPlaybackSpeed(); } mTomahawkListAdapter.getProgressBar().setProgress( (int) ((float) currentPosition / duration * mTomahawkListAdapter.getProgressBar().getMax())); } } });