List of usage examples for android.support.v4.media.session PlaybackStateCompat getPlaybackSpeed
public float getPlaybackSpeed()
From source file:org.runbuddy.tomahawk.views.PlaybackPanel.java
private void init() { mTextViewContainer = (FrameLayout) findViewById(R.id.textview_container); mPanelContainer = findViewById(R.id.panel_container); mStationContainer = findViewById(R.id.station_container); mStationContainerInner = findViewById(R.id.station_container_inner); mStationContainerInner.addOnLayoutChangeListener(mStationLayoutChangeListener); mArtistNameButton = (FrameLayout) mTextViewContainer.findViewById(R.id.artist_name_button); mArtistTextView = (TextView) mArtistNameButton.findViewById(R.id.artist_textview); mTrackTextView = (TextView) mTextViewContainer.findViewById(R.id.track_textview); mCompletionTimeTextView = (TextView) findViewById(R.id.completiontime_textview); mCurrentTimeTextView = (TextView) findViewById(R.id.currenttime_textview); mSeekTimeTextView = (TextView) findViewById(R.id.seektime_textview); mStationTextView = (TextView) findViewById(R.id.station_textview); mResolverImageView = (ImageView) findViewById(R.id.resolver_imageview); mPlayButton = (ImageView) findViewById(R.id.play_button); mPauseButton = (ImageView) findViewById(R.id.pause_button); mProgressBar = (ProgressBar) findViewById(R.id.progressbar); mProgressBarThumb = findViewById(R.id.progressbar_thumb); mPlayPauseButtonContainer = (FrameLayout) findViewById(R.id.circularprogressbar_container); mPlayPauseButton = (CircularProgressView) mPlayPauseButtonContainer.findViewById(R.id.circularprogressbar); mProgressBarUpdater = new ProgressBarUpdater(new ProgressBarUpdater.UpdateProgressRunnable() { @Override//from ww w . j av a 2s. co m 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)); } }); }
From source file:nuclei.media.MediaPlayerController.java
@Override public int getCurrentPosition() { if (isEquals()) { PlaybackStateCompat state = mMediaControls.getPlaybackState(); if (state != null) { // KJB: NOTE: Pulled from media compat library // For some reason, it seems, that only API 21 doesn't do something equivalent // of this. weird. // Just to be safe, since this is important, doing it here. // It's a little redundant... but, I don't see how this would hurt anything // if it were executed twice (so long as getLastPositionUpdateTime is correct) // TODO: revisit this after support library 25.1.1 try { if ((state.getState() == PlaybackStateCompat.STATE_PLAYING || state.getState() == PlaybackStateCompat.STATE_FAST_FORWARDING || state.getState() == PlaybackStateCompat.STATE_REWINDING)) { final long updateTime = state.getLastPositionUpdateTime(); final long currentTime = SystemClock.elapsedRealtime(); if (updateTime > 0) { final float speed = state.getPlaybackSpeed(); final long duration = getDuration(); long position = (long) (speed * (currentTime - updateTime)) + state.getPosition(); if (duration >= 0 && position > duration) { position = duration; } else if (position < 0) { position = 0; }//from w ww .j a v a2s.c om return (int) position; } } } catch (Exception err) { // because weird things happen sometimes :( LOG.e("Error calculating latest position", err); } return (int) state.getPosition(); } } return -1; }