Search in sources :

Example 21 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class FullScreenPlayerActivity method updatePlaybackState.

private void updatePlaybackState(PlaybackStateCompat state) {
    if (state == null) {
        return;
    }
    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);
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 22 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class PlaybackControlsFragment method onConnected.

public void onConnected() {
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    LogHelper.d(TAG, "onConnected, mediaController==null? ", controller == null);
    if (controller != null) {
        onMetadataChanged(controller.getMetadata());
        onPlaybackStateChanged(controller.getPlaybackState());
        controller.registerCallback(mCallback);
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 23 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class PlaybackControlsFragment method onStop.

@Override
public void onStop() {
    super.onStop();
    LogHelper.d(TAG, "fragment.onStop");
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    if (controller != null) {
        controller.unregisterCallback(mCallback);
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 24 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class TvBrowseFragment method initializeWithMediaId.

public void initializeWithMediaId(String mediaId) {
    LogHelper.d(TAG, "subscribeToData");
    // fetch browsing information to fill the listview:
    mMediaBrowser = mMediaFragmentListener.getMediaBrowser();
    if (mediaId == null) {
        mediaId = mMediaBrowser.getRoot();
    }
    subscribeToMediaId(mediaId, mSubscriptionCallback);
    // Add MediaController callback so we can redraw the list when metadata changes:
    MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(getActivity());
    if (mediaController != null) {
        mediaController.registerCallback(mMediaControllerCallback);
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 25 with MediaControllerCompat

use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.

the class TvPlaybackActivity method onStop.

@Override
protected void onStop() {
    super.onStop();
    LogHelper.d(TAG, "Activity onStop");
    MediaControllerCompat controllerCompat = MediaControllerCompat.getMediaController(TvPlaybackActivity.this);
    if (controllerCompat != null) {
        controllerCompat.unregisterCallback(mMediaControllerCallback);
    }
    mMediaBrowser.disconnect();
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Aggregations

MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)27 FragmentActivity (android.support.v4.app.FragmentActivity)3 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)3 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)3 Intent (android.content.Intent)2 ListRow (android.support.v17.leanback.widget.ListRow)2 ListRowPresenter (android.support.v17.leanback.widget.ListRowPresenter)2 MediaBrowserCompat (android.support.v4.media.MediaBrowserCompat)2 MediaMetadataCompat (android.support.v4.media.MediaMetadataCompat)2 View (android.view.View)2 AbstractDetailsDescriptionPresenter (android.support.v17.leanback.widget.AbstractDetailsDescriptionPresenter)1 Action (android.support.v17.leanback.widget.Action)1 HeaderItem (android.support.v17.leanback.widget.HeaderItem)1 OnActionClickedListener (android.support.v17.leanback.widget.OnActionClickedListener)1 OnItemViewClickedListener (android.support.v17.leanback.widget.OnItemViewClickedListener)1 PlaybackControlsRow (android.support.v17.leanback.widget.PlaybackControlsRow)1 PlayPauseAction (android.support.v17.leanback.widget.PlaybackControlsRow.PlayPauseAction)1 SkipNextAction (android.support.v17.leanback.widget.PlaybackControlsRow.SkipNextAction)1 SkipPreviousAction (android.support.v17.leanback.widget.PlaybackControlsRow.SkipPreviousAction)1 PlaybackControlsRowPresenter (android.support.v17.leanback.widget.PlaybackControlsRowPresenter)1