Example usage for android.support.v4.media.session MediaControllerCompat getExtras

List of usage examples for android.support.v4.media.session MediaControllerCompat getExtras

Introduction

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

Prototype

public Bundle getExtras() 

Source Link

Usage

From source file:rocks.stalin.android.app.ui.PlaybackControlsFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;//from www  .  j a  v a 2s  . co m
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

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

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;//  w w  w  .  java2 s  . com
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

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

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;/*w  ww  .j  a va2  s.c  o m*/
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

    if (enablePlay) {
        mPlayPause.setImageDrawable(
                ActivityCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_36dp));
    } else {
        mPlayPause.setImageDrawable(ActivityCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_36dp));
    }

    MediaControllerCompat controller = mMediaControllerProvider.getSupportMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

From source file:com.murati.oszk.audiobook.ui.PlaybackControlsFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;/*from w w  w  . j av  a  2  s  .co  m*/
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        String message = state.getErrorMessage().toString();
        LogHelper.e(TAG, "error playbackstate: ", message);

        try {
            //Set smarter messages with state processing
            boolean offline = !NetworkHelper.isOnline(this.getActivity().getBaseContext());
            if (message.contains("EACCES")) {
                message = String.format("%s - %s", getString(R.string.notification_playback_track_error),
                        getString(R.string.notification_storage_permission_required));

                OfflineBookService.isPermissionGranted(this.getActivity());
            }

            if (offline && message.contains("Unable to connect to http")) {
                message = String.format("%s - %s", getString(R.string.notification_playback_track_error),
                        getString(R.string.notification_offline));
            }
        } catch (Exception ex) {
            Log.d(TAG, ex.getMessage());
        }

        Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

From source file:com.appdevper.mediaplayer.ui.PlaybackControlsFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;//w  ww  . ja v a2  s  . c  o m
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackState.STATE_PAUSED:
    case PlaybackState.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackState.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

From source file:com.classiqo.nativeandroid_32bitz.ui.PlaybackControlsFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);

    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");

        return;/*from ww w.j  av a  2 s . c o  m*/
    }

    if (state == null) {
        return;
    }

    boolean enablePlay = false;

    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        LogHelper.e(TAG, "error playbackState: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
    String extraInfo = null;

    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);

        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}

From source file:com.pi.android.brainbeats.ui.PlaybackControlsFragment.java

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null,"
                + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;// www. j  a  v a  2 s. c  o  m
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
    case PlaybackStateCompat.STATE_PAUSED:
    case PlaybackStateCompat.STATE_STOPPED:
        enablePlay = true;
        break;
    case PlaybackStateCompat.STATE_ERROR:
        LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
        Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
        break;
    }

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

    MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    final MediaMetadataCompat metadata = controller.getMetadata();
    if (metadata != null) {
        updateTags(metadata);
    }
    setExtraInfo(extraInfo);
}

From source file:org.runbuddy.tomahawk.views.PlaybackPanel.java

public void setMediaController(MediaControllerCompat mediaController) {
    mMediaController = mediaController;/*  ww w.j  a  v  a 2  s.co  m*/
    String playbackManagerId = mediaController.getExtras()
            .getString(PlaybackService.EXTRAS_KEY_PLAYBACKMANAGER);
    mPlaybackManager = PlaybackManager.getByKey(playbackManagerId);
    if (mediaController.getMetadata() != null) {
        updateMetadata(mediaController.getMetadata());
    }
    updatePlaybackState(mediaController.getPlaybackState());
}

From source file:com.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;//from   w  ww.  jav  a  2s  .  co  m
    }

    //TODO: Fix Time for current state

    mLastPlaybackState = state;
    MediaControllerCompat controllerCompat = MediaControllerCompat
            .getMediaController(FullScreenPlayerActivity.this);
    if (controllerCompat != null && controllerCompat.getExtras() != null) {
        String castName = controllerCompat.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);
}