use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class TvPlaybackFragment method setupRows.
private void setupRows() {
PlaybackControlsRowPresenter playbackControlsRowPresenter;
playbackControlsRowPresenter = new PlaybackControlsRowPresenter(new DescriptionPresenter());
playbackControlsRowPresenter.setOnActionClickedListener(new OnActionClickedListener() {
public void onActionClicked(Action action) {
if (getActivity() == null) {
return;
}
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
if (controller == null) {
return;
}
MediaControllerCompat.TransportControls controls = controller.getTransportControls();
if (action.getId() == mPlayPauseAction.getId()) {
if (mPlayPauseAction.getIndex() == PlayPauseAction.PLAY) {
controls.play();
} else {
controls.pause();
}
} else if (action.getId() == mSkipNextAction.getId()) {
controls.skipToNext();
resetPlaybackRow();
} else if (action.getId() == mSkipPreviousAction.getId()) {
controls.skipToPrevious();
resetPlaybackRow();
}
if (action instanceof PlaybackControlsRow.MultiAction) {
((PlaybackControlsRow.MultiAction) action).nextIndex();
notifyChanged(action);
}
}
});
mPresenterSelector.addClassPresenter(PlaybackControlsRow.class, playbackControlsRowPresenter);
}
use of android.support.v4.media.session.MediaControllerCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaIDHelper method isMediaItemPlaying.
/**
* Determine if media item is playing (matches the currently playing media item).
*
* @param context for retrieving the {@link MediaControllerCompat}
* @param mediaItem to compare to currently playing {@link MediaBrowserCompat.MediaItem}
* @return boolean indicating whether media item matches currently playing media item
*/
public static boolean isMediaItemPlaying(Activity context, MediaBrowserCompat.MediaItem mediaItem) {
// Media item is considered to be playing or paused based on the controller's current
// media id
MediaControllerCompat controller = MediaControllerCompat.getMediaController(context);
if (controller != null && controller.getMetadata() != null) {
String currentPlayingMediaId = controller.getMetadata().getDescription().getMediaId();
String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(mediaItem.getDescription().getMediaId());
if (currentPlayingMediaId != null && TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
return true;
}
}
return false;
}
Aggregations