Example usage for android.support.v4.media.session PlaybackStateCompat STATE_REWINDING

List of usage examples for android.support.v4.media.session PlaybackStateCompat STATE_REWINDING

Introduction

In this page you can find the example usage for android.support.v4.media.session PlaybackStateCompat STATE_REWINDING.

Prototype

int STATE_REWINDING

To view the source code for android.support.v4.media.session PlaybackStateCompat STATE_REWINDING.

Click Source Link

Document

State indicating this item is currently rewinding.

Usage

From source file:com.achep.acdisplay.services.media.MediaController2KitKat.java

@NonNull
static SparseIntArray generatePlaybackCompatSparse() {
    SparseIntArray sia = new SparseIntArray();
    sia.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
    sia.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
    sia.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
    sia.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
    sia.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
    sia.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING, PlaybackStateCompat.STATE_FAST_FORWARDING);
    sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
    sia.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS, PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);
    return sia;//ww  w.j  ava2 s.c  o m
}

From source file:com.bullmobi.message.services.media.MediaController2KitKat.java

/**
 * {@inheritDoc}//  w ww  . j  a v  a2s.  co m
 */
protected MediaController2KitKat(@NonNull Activity activity) {
    super(activity);

    SparseIntArray cachedStateSparse = sStateSparse.get();
    if (cachedStateSparse == null) {
        mStateSparse = new SparseIntArray();
        mStateSparse.put(RemoteControlClient.PLAYSTATE_BUFFERING, PlaybackStateCompat.STATE_BUFFERING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PLAYING, PlaybackStateCompat.STATE_PLAYING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_PAUSED, PlaybackStateCompat.STATE_PAUSED);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_ERROR, PlaybackStateCompat.STATE_ERROR);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_REWINDING, PlaybackStateCompat.STATE_REWINDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_FAST_FORWARDING,
                PlaybackStateCompat.STATE_FAST_FORWARDING);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_NEXT);
        mStateSparse.put(RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS,
                PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS);

        // Cache sparse array
        sStateSparse = new WeakReference<>(mStateSparse);
    } else {
        mStateSparse = cachedStateSparse;
    }
}

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;
                        }/*w  w w  .  j a v a  2 s  . 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;
}

From source file:android.support.v17.leanback.media.MediaControllerAdapter.java

@Override
public boolean isPlaying() {
    if (mController.getPlaybackState() == null) {
        return false;
    }/*from  w  w  w.  ja  v a2 s  .c  o  m*/
    return mController.getPlaybackState().getState() == PlaybackStateCompat.STATE_PLAYING
            || mController.getPlaybackState().getState() == PlaybackStateCompat.STATE_FAST_FORWARDING
            || mController.getPlaybackState().getState() == PlaybackStateCompat.STATE_REWINDING;
}

From source file:androidx.media.MediaUtils2.java

static int toPlayerState(int playbackStateCompatState) {
    switch (playbackStateCompatState) {
    case PlaybackStateCompat.STATE_ERROR:
        return MediaPlayerBase.PLAYER_STATE_ERROR;
    case PlaybackStateCompat.STATE_NONE:
        return MediaPlayerBase.PLAYER_STATE_IDLE;
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
    case PlaybackStateCompat.STATE_BUFFERING: // means paused for buffering.
        return MediaPlayerBase.PLAYER_STATE_PAUSED;
    case PlaybackStateCompat.STATE_FAST_FORWARDING:
    case PlaybackStateCompat.STATE_PLAYING:
    case PlaybackStateCompat.STATE_REWINDING:
    case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT:
    case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS:
    case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM:
    case PlaybackStateCompat.STATE_CONNECTING: // Note: there's no perfect match for this.
        return MediaPlayerBase.PLAYER_STATE_PLAYING;
    }//  w  w w  .  j a v a 2  s .  c o m
    return MediaPlayerBase.PLAYER_STATE_ERROR;
}

From source file:com.mylovemhz.simplay.MusicService.java

public void rewind() {
    if (currentState == State.STARTED || currentState == State.PAUSED || currentState == State.PREPARED
            || currentState == State.COMPLETED) {
        if (mediaPlayer.getCurrentPosition() > TIME_FFWD_RWD) {
            mediaPlayer.seekTo(mediaPlayer.getCurrentPosition() - TIME_FFWD_RWD);
            updateSessionState(PlaybackStateCompat.STATE_REWINDING);
        }/* w w  w.ja v  a 2  s . c o m*/
    }
}

From source file:com.mylovemhz.simplay.MusicService.java

public boolean isPlaying() {
    int state = getPlaybackState().getState();
    return state == PlaybackStateCompat.STATE_BUFFERING || state == PlaybackStateCompat.STATE_FAST_FORWARDING
            || state == PlaybackStateCompat.STATE_PLAYING || state == PlaybackStateCompat.STATE_REWINDING;
}

From source file:com.example.android.leanback.MediaSessionService.java

private void rewind() {
    // To support rewind action, the mRewindSpeedFactors must be provided through
    // setRewindSpeedFactors() method;
    if (mRewindSpeedFactors == null) {
        if (DEBUG) {
            Log.d(TAG, "RewindSpeedFactors are not set");
        }/*  w ww . j a v  a2s . co m*/
        return;
    }

    // Perform rewind operation using different speed.
    if (mIsRewindBegin) {
        // record end time stamp for previous rewind operation.
        mRewindEndTime = SystemClock.elapsedRealtime();
        long position = mRewindStartPosition
                + (long) mRewindSpeedFactors[mRewindSpeedFactorIndex - 1] * (mRewindEndTime - mRewindStartTime);
        if (DEBUG) {
            Log.e(TAG, "Last Rewind Operation Position" + position);
        }
        mPlayer.seekTo((int) position);

        // Set new start status
        mRewindStartPosition = position;
        mRewindStartTime = mRewindEndTime;
        // It is still in rewind state, so mIsRewindBegin remains to be true.
    }

    // Perform rewind operation using the first speed set.
    if (!mIsRewindBegin) {
        mRewindStartPosition = getCurrentPosition();
        Log.e("REWIND_BEGIN", "REWIND BEGIN PLACE " + mRewindStartPosition);
        mIsRewindBegin = true;
        mRewindStartTime = SystemClock.elapsedRealtime();
    }

    // Toggle the flag to indicate rewind status.
    mIsRewinding = true;

    // Pause the player but won't update the UI status.
    mPlayer.pause();

    // Update playback state, mIsRewinding will be reset to false inside of it.
    mMediaSession.setPlaybackState(createPlaybackStateBuilder(PlaybackStateCompat.STATE_REWINDING).build());

    mRewindSpeedFactorIndex += 1;
    if (mRewindSpeedFactorIndex > mRewindSpeedFactors.length - 1) {
        mRewindSpeedFactorIndex = mRewindSpeedFactors.length - 1;
    }
}