Example usage for android.media.session PlaybackState STATE_NONE

List of usage examples for android.media.session PlaybackState STATE_NONE

Introduction

In this page you can find the example usage for android.media.session PlaybackState STATE_NONE.

Prototype

int STATE_NONE

To view the source code for android.media.session PlaybackState STATE_NONE.

Click Source Link

Document

This is the default playback state and indicates that no media has been added yet, or the performer has been reset and has no content to play.

Usage

From source file:info.tongrenlu.MediaNotificationManager.java

public void onPlaybackStateChanged(PlaybackStateCompat state) {
    mPlaybackState = state;/*from  w ww . j a v  a2 s .com*/
    Log.d(TAG, "Received new playback state" + state);
    if (state != null && (state.getState() == PlaybackState.STATE_STOPPED
            || state.getState() == PlaybackState.STATE_NONE)) {
        stopNotification();
    } else {
        Notification notification = createNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }
}

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

/**
 * Check if the MediaSession is active and in a "playback-able" state
 * (not NONE and not STOPPED).// w w  w  .j  a  v  a  2s.com
 *
 * @return true if the MediaSession's state requires playback controls to be visible.
 */
protected boolean shouldShowControls() {
    MediaControllerCompat mediaController = mMediaController;
    if (mediaController == null || mediaController.getMetadata() == null
            || mediaController.getPlaybackState() == null) {
        return false;
    }
    switch (mediaController.getPlaybackState().getState()) {
    case PlaybackState.STATE_ERROR:
    case PlaybackState.STATE_NONE:
    case PlaybackState.STATE_STOPPED:
        return false;
    default:
        return true;
    }
}

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

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (state == null) {
        return;//from  ww w  .jav a 2 s  .c  o 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:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java

private void createMediaSession() {
    if (mSession == null) {
        mSession = new MediaSession(getActivity(), "LeanbackSampleApp");
        mSession.setCallback(new MediaSessionCallback());
        mSession.setFlags(FLAG_HANDLES_MEDIA_BUTTONS | FLAG_HANDLES_TRANSPORT_CONTROLS);

        mSession.setActive(true);//from www.j  a v  a2s .  c  om

        // Set the Activity's MediaController used to invoke transport controls / adjust volume.
        getActivity().setMediaController(new MediaController(getActivity(), mSession.getSessionToken()));
        setPlaybackState(PlaybackState.STATE_NONE);
    }
}

From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java

private void createMediaSession() {
    Log.d(TAG, "createMediaSession");
    if (mSession == null) {

        mSession = new MediaSession(getActivity(), getResources().getString(R.string.app_name));
        mSession.setCallback(new MediaSessionCallback());
        mSession.setFlags(FLAG_HANDLES_MEDIA_BUTTONS | FLAG_HANDLES_TRANSPORT_CONTROLS);

        mSession.setActive(true);//from  ww w  .j  a  v  a2s.  c  o  m

        // Set the Activity's MediaController used to invoke transport controls / adjust volume.
        getActivity().setMediaController(new MediaController(getActivity(), mSession.getSessionToken()));
        setPlaybackState(PlaybackState.STATE_NONE);

    }

}

From source file:de.kraenksoft.c3tv.ui.PlaybackOverlayFragment.java

private void playPause(boolean doPlay) {
    if (getPlaybackState() == PlaybackState.STATE_NONE) {
        setupCallbacks();// w  w  w.  j a v  a  2s  .c  o  m
    }

    if (doPlay && getPlaybackState() != PlaybackState.STATE_PLAYING) {
        if (mPosition > 0) {
            mVideoView.seekTo(mPosition);
        }
        mVideoView.start();
        mStartTimeMillis = System.currentTimeMillis();
        setPlaybackState(PlaybackState.STATE_PLAYING);
    } else {
        int timeElapsedSinceStart = (int) (System.currentTimeMillis() - mStartTimeMillis);
        setPosition(mPosition + timeElapsedSinceStart);
        mVideoView.pause();
        setPlaybackState(PlaybackState.STATE_PAUSED);
    }
}

From source file:org.mythtv.android.presentation.view.fragment.TvPlaybackOverlayFragment.java

private void playPause(boolean doPlay) {

    if (getPlaybackState() == PlaybackState.STATE_NONE) {

        setupCallbacks();/*from   w  ww.j av  a2  s  . c  o  m*/

    }

    if (doPlay && getPlaybackState() != PlaybackState.STATE_PLAYING) {

        if (mPosition > 0) {

            mVideoView.seekTo(mPosition);

        }

        mVideoView.start();
        mStartTimeMillis = System.currentTimeMillis();
        setPlaybackState(PlaybackState.STATE_PLAYING);

    } else {

        int timeElapsedSinceStart = (int) (System.currentTimeMillis() - mStartTimeMillis);
        setPosition(mPosition + timeElapsedSinceStart);
        mVideoView.pause();
        setPlaybackState(PlaybackState.STATE_PAUSED);

    }

}

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

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//w ww .  j a v  a 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 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:com.aengbee.android.leanback.ui.PlaybackOverlayCustomFragment.java

private void createMediaSession() {
    if (mSession == null) {
        mSession = new MediaSessionCompat(getActivity(), "LeanbackSampleApp");
        mSession.setCallback(new MediaSessionCallback());
        mSession.setFlags(FLAG_HANDLES_MEDIA_BUTTONS | FLAG_HANDLES_TRANSPORT_CONTROLS);
        mSession.setActive(true);//  w  ww .  ja  v  a2 s .  c  o  m

        // Set the Activity's MediaController used to invoke transport controls / adjust volume.
        try {
            ((FragmentActivity) getActivity()).setSupportMediaController(
                    new MediaControllerCompat(getActivity(), mSession.getSessionToken()));
            setPlaybackState(PlaybackState.STATE_NONE);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.aengbee.android.leanback.ui.PlaybackOverlayCustomFragment.java

private void play() {
    // Request audio focus whenever we resume playback
    // because the app might have abandoned audio focus due to the AUDIOFOCUS_LOSS.
    requestAudioFocus();// w ww . j a v a 2s  .com

    if (mPlayer == null) {
        setPlaybackState(PlaybackState.STATE_NONE);
        return;
    }
    if (!mGlue.isMediaPlaying()) {
        mPlayer.getPlayerControl().start();
        setPlaybackState(PlaybackState.STATE_PLAYING);
    }
}