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);
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations