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

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

Introduction

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

Prototype

@Actions
public long getActions() 

Source Link

Document

Get the current actions available on this session.

Usage

From source file:com.wojtechnology.sunami.MediaSessionCompatHelper.java

private static void ensureTransportControls(MediaSessionCompat session, PlaybackStateCompat playbackState) {
    long actions = playbackState.getActions();
    Object remoteObj = session.getRemoteControlClient();
    if (actions != 0 && remoteObj != null) {

        int transportControls = 0;

        if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS;
        }/*from  w ww  .  jav  a2  s  .c o m*/

        if ((actions & PlaybackStateCompat.ACTION_REWIND) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_REWIND;
        }

        if ((actions & PlaybackStateCompat.ACTION_PLAY) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PLAY;
        }

        if ((actions & PlaybackStateCompat.ACTION_PLAY_PAUSE) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE;
        }

        if ((actions & PlaybackStateCompat.ACTION_PAUSE) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PAUSE;
        }

        if ((actions & PlaybackStateCompat.ACTION_STOP) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_STOP;
        }

        if ((actions & PlaybackStateCompat.ACTION_FAST_FORWARD) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD;
        }

        if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_NEXT;
        }

        if ((actions & PlaybackStateCompat.ACTION_SEEK_TO) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE;
        }

        if ((actions & PlaybackStateCompat.ACTION_SET_RATING) != 0) {
            transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_RATING;
        }

        ((RemoteControlClient) remoteObj).setTransportControlFlags(transportControls);
    }
}

From source file:org.runbuddy.tomahawk.ui.fragments.PlaybackFragment.java

public void showSwipeHints(PlaybackStateCompat playbackState) {
    if (!mSwipeHintsShown && mSwipeHintLeft != null && mSwipeHintRight != null && mSwipeHintBottom != null) {
        mSwipeHintsShown = true;//from   w ww.ja  v  a  2s .  c  o  m
        AnimationUtils.fade(mSwipeHintBottom, AnimationUtils.DURATION_PLAYBACKTOPPANEL, true);
        long actions = playbackState.getActions();
        final boolean hasPreviousEntry = (actions & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0;
        final boolean hasNextEntry = (actions & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0;
        if (hasPreviousEntry) {
            AnimationUtils.fade(mSwipeHintLeft, AnimationUtils.DURATION_PLAYBACKTOPPANEL, true);
        }
        if (hasNextEntry) {
            AnimationUtils.fade(mSwipeHintRight, AnimationUtils.DURATION_PLAYBACKTOPPANEL, true);
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mSwipeHintsShown = false;
                if (hasPreviousEntry) {
                    AnimationUtils.fade(mSwipeHintLeft, AnimationUtils.DURATION_PLAYBACKTOPPANEL, false);
                }
                if (hasNextEntry) {
                    AnimationUtils.fade(mSwipeHintRight, AnimationUtils.DURATION_PLAYBACKTOPPANEL, false);
                }
                AnimationUtils.fade(mSwipeHintBottom, AnimationUtils.DURATION_PLAYBACKTOPPANEL, false);
            }
        }, 1500);
    }
}

From source file:com.example.android.AudioArchive.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from  www .j  a v a 2  s  . co  m
    }
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);

        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);

        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);

        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);

        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.example.android.mediabrowserservice.QueueFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (state == null) {
        return;/*  w w w  . ja v  a 2  s  .  co  m*/
    }
    mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId());
    mQueueAdapter.notifyDataSetChanged();
    boolean enablePlay = false;
    StringBuilder statusBuilder = new StringBuilder();
    switch (state.getState()) {
    case PlaybackState.STATE_PLAYING:
        statusBuilder.append("playing");
        enablePlay = false;
        break;
    case PlaybackState.STATE_PAUSED:
        statusBuilder.append("paused");
        enablePlay = true;
        break;
    case PlaybackState.STATE_STOPPED:
        statusBuilder.append("ended");
        enablePlay = true;
        break;
    case PlaybackState.STATE_ERROR:
        statusBuilder.append("error: ").append(state.getErrorMessage());
        break;
    case PlaybackState.STATE_BUFFERING:
        statusBuilder.append("buffering");
        break;
    case PlaybackState.STATE_NONE:
        statusBuilder.append("none");
        enablePlay = false;
        break;
    case PlaybackState.STATE_CONNECTING:
        statusBuilder.append("connecting");
        break;
    default:
        statusBuilder.append(mPlaybackState);
    }
    statusBuilder.append(" -- At position: ").append(state.getPosition());
    LogHelper.d(TAG, statusBuilder.toString());

    if (enablePlay) {
        mPlayPause.setImageDrawable(
                ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_white_24dp));
    } else {
        mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_white_24dp));
    }

    mSkipPrevious.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0);
    mSkipNext.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0);

    LogHelper.d(TAG, "Queue From MediaController *** Title " + mMediaController.getQueueTitle() + "\n: Queue: "
            + mMediaController.getQueue() + "\n Metadata " + mMediaController.getMetadata());
}

From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from  w  w w  .  j  a  va  2s  .com
    }
    mLastPlaybackState = state;
    String castName = mMediaController.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
    String line3Text = "";
    if (castName != null) {
        line3Text = getResources().getString(R.string.casting_to_device, castName);
    }
    mLine3.setText(line3Text);

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.example.android.supportv4.media.QueueFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    Log.d(TAG, "onPlaybackStateChanged " + state);
    if (state == null) {
        return;/*  w  w  w .  j  a  v  a  2 s  .c  om*/
    }
    mQueueAdapter.setActiveQueueItemId(state.getActiveQueueItemId());
    mQueueAdapter.notifyDataSetChanged();
    boolean enablePlay = false;
    StringBuilder statusBuilder = new StringBuilder();
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        statusBuilder.append("playing");
        enablePlay = false;
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        statusBuilder.append("paused");
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_STOPPED:
        statusBuilder.append("ended");
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        statusBuilder.append("error: ").append(state.getErrorMessage());
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        statusBuilder.append("buffering");
        break;
    case PlaybackStateCompat.STATE_NONE:
        statusBuilder.append("none");
        enablePlay = false;
        break;
    case PlaybackStateCompat.STATE_CONNECTING:
        statusBuilder.append("connecting");
        break;
    default:
        statusBuilder.append(mPlaybackState);
    }
    statusBuilder.append(" -- At position: ").append(state.getPosition());
    Log.d(TAG, statusBuilder.toString());

    if (enablePlay) {
        mPlayPause.setImageDrawable(
                getActivity().getResources().getDrawable(R.drawable.ic_play_arrow_white_24dp));
    } else {
        mPlayPause.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.ic_pause_white_24dp));
    }

    mSkipPrevious.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0);
    mSkipNext.setEnabled((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0);

    Log.d(TAG, "Queue From MediaController *** Title " + mMediaController.getQueueTitle() + "\n: Queue: "
            + mMediaController.getQueue() + "\n Metadata " + mMediaController.getMetadata());
}

From source file:info.tongrenlu.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/* w ww. jav a 2 s  . c o m*/
    }
    Log.d(TAG, "updatePlaybackState, playback state=" + state.getState());
    mLastPlaybackState = state;

    mLine3.setText("");

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        //                mPlayPause.setImageDrawable(mPauseDrawable);
        Glide.with(this).load(R.drawable.ic_pause_white_48dp).into(mPlayPause);
        mControllers.setVisibility(View.VISIBLE);
        scheduleProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(View.VISIBLE);
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        //                mPlayPause.setImageDrawable(mPlayDrawable);
        Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause);
        stopProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(View.INVISIBLE);
        mPlayPause.setVisibility(View.VISIBLE);
        Glide.with(this).load(R.drawable.ic_play_arrow_white_48dp).into(mPlayPause);
        stopProgressUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(View.INVISIBLE);
        mLoading.setVisibility(View.VISIBLE);
        mLine3.setText(R.string.loading);
        stopProgressUpdate();
        break;
    default:
        Log.d(TAG, "Unhandled state " + state.getState());
    }

    mSkipNext.setVisibility((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? View.INVISIBLE
            : View.VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? View.INVISIBLE
                    : View.VISIBLE);
}

From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//ww w. ja  v a 2s.c om
    }
    mLastPlaybackState = state;
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackState.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackState.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackState.STATE_NONE:
    case PlaybackState.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackState.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext
            .setVisibility((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;/*from   w ww. ja  va 2s. c  o  m*/
    }
    mLastPlaybackState = state;
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine3.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine3.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}

From source file:com.bayapps.android.robophish.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from ww  w . j  ava  2s .c o m
    }
    mLastPlaybackState = state;
    if (getSupportMediaController() != null && getSupportMediaController().getExtras() != null) {
        String castName = getSupportMediaController().getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        String line3Text = castName == null ? ""
                : getResources().getString(R.string.casting_to_device, castName);
        mLine5.setText(line3Text);
    }

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PLAYING:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPauseDrawable);
        mControllers.setVisibility(VISIBLE);
        scheduleSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_PAUSED:
        mControllers.setVisibility(VISIBLE);
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_NONE:
    case PlaybackStateCompat.STATE_STOPPED:
        mLoading.setVisibility(INVISIBLE);
        mPlayPause.setVisibility(VISIBLE);
        mPlayPause.setImageDrawable(mPlayDrawable);
        stopSeekbarUpdate();
        break;
    case PlaybackStateCompat.STATE_BUFFERING:
        mPlayPause.setVisibility(INVISIBLE);
        mLoading.setVisibility(VISIBLE);
        mLine5.setText(R.string.loading);
        stopSeekbarUpdate();
        break;
    default:
        LogHelper.d(TAG, "Unhandled state ", state.getState());
    }

    mSkipNext.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) == 0 ? INVISIBLE : VISIBLE);
    mSkipPrev.setVisibility(
            (state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) == 0 ? INVISIBLE : VISIBLE);
}