Search in sources :

Example 11 with MediaControllerCompat

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

the class MediaBrowserFragment method onStop.

@Override
public void onStop() {
    super.onStop();
    MediaBrowserCompat mediaBrowser = mMediaFragmentListener.getMediaBrowser();
    if (mediaBrowser != null && mediaBrowser.isConnected() && mMediaId != null) {
        mediaBrowser.unsubscribe(mMediaId);
    }
    MediaControllerCompat controller = ((FragmentActivity) getActivity()).getSupportMediaController();
    if (controller != null) {
        controller.unregisterCallback(mMediaControllerCallback);
    }
    this.getActivity().unregisterReceiver(mConnectivityChangeReceiver);
}
Also used : MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) FragmentActivity(android.support.v4.app.FragmentActivity) MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 12 with MediaControllerCompat

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

the class TvPlaybackFragment method updatePlaybackState.

protected void updatePlaybackState(PlaybackStateCompat state) {
    if (mPlaybackControlsRow == null) {
        // We only update playback state after we get a valid metadata.
        return;
    }
    mLastPosition = state.getPosition();
    mLastPositionUpdateTime = state.getLastPositionUpdateTime();
    switch(state.getState()) {
        case PlaybackStateCompat.STATE_PLAYING:
            startProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            stopProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
            break;
    }
    MediaControllerCompat controller = getActivity().getSupportMediaController();
    updatePlayListRow(controller.getQueue());
    mRowsAdapter.notifyArrayItemRangeChanged(mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 13 with MediaControllerCompat

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

the class MediaNotificationManager method updateSessionToken.

/**
     * Update the state based on a change on the session token. Called either when
     * we are running for the first time or when the media session owner has destroyed the session
     * (see {@link android.media.session.MediaController.Callback#onSessionDestroyed()})
     */
private void updateSessionToken() throws RemoteException {
    MediaSessionCompat.Token freshToken = mService.getSessionToken();
    if (mSessionToken == null && freshToken != null || mSessionToken != null && !mSessionToken.equals(freshToken)) {
        if (mController != null) {
            mController.unregisterCallback(mCb);
        }
        mSessionToken = freshToken;
        if (mSessionToken != null) {
            mController = new MediaControllerCompat(mService, mSessionToken);
            mTransportControls = mController.getTransportControls();
            if (mStarted) {
                mController.registerCallback(mCb);
            }
        }
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)

Example 14 with MediaControllerCompat

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

the class FullScreenPlayerActivity method connectToSession.

private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
    MediaControllerCompat mediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token);
    if (mediaController.getMetadata() == null) {
        finish();
        return;
    }
    setSupportMediaController(mediaController);
    mediaController.registerCallback(mCallback);
    PlaybackStateCompat state = mediaController.getPlaybackState();
    updatePlaybackState(state);
    MediaMetadataCompat metadata = mediaController.getMetadata();
    if (metadata != null) {
        updateMediaDescription(metadata.getDescription());
        updateDuration(metadata);
    }
    updateProgress();
    if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING || state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
        scheduleSeekbarUpdate();
    }
}
Also used : PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 15 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 = getActivity().getSupportMediaController();
    if (mediaController != null) {
        mediaController.registerCallback(mMediaControllerCallback);
    }
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Aggregations

MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)20 FragmentActivity (android.support.v4.app.FragmentActivity)10 MediaSessionCompat (android.support.v4.media.session.MediaSessionCompat)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 PlaybackStateCompat (android.support.v4.media.session.PlaybackStateCompat)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