use of android.support.v4.media.MediaDescriptionCompat in project AntennaPod by AntennaPod.
the class CustomMRControllerDialog method fetchArt.
private Pair<Bitmap, Integer> fetchArt(@NonNull MediaDescriptionCompat description) {
Bitmap iconBitmap = description.getIconBitmap();
Uri iconUri = description.getIconUri();
Bitmap art = null;
if (iconBitmap != null) {
art = iconBitmap;
} else if (iconUri != null) {
try {
art = Glide.with(getContext().getApplicationContext()).load(iconUri.toString()).asBitmap().diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY).into(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL).get();
} catch (InterruptedException | ExecutionException e) {
Log.e(TAG, "Image art load failed", e);
}
}
int backgroundColor = 0;
if (art != null && art.getWidth() * 9 < art.getHeight() * 16) {
// Portrait art requires dominant color as background color.
Palette palette = new Palette.Builder(art).maximumColorCount(1).generate();
backgroundColor = palette.getSwatches().isEmpty() ? 0 : palette.getSwatches().get(0).getRgb();
}
return new Pair<>(art, backgroundColor);
}
use of android.support.v4.media.MediaDescriptionCompat in project AntennaPod by AntennaPod.
the class CustomMRControllerDialog method updateViews.
private void updateViews() {
if (!viewsCreated || token == null || mediaController == null) {
rootView.setVisibility(View.GONE);
return;
}
MediaMetadataCompat metadata = mediaController.getMetadata();
MediaDescriptionCompat description = metadata == null ? null : metadata.getDescription();
if (description == null) {
rootView.setVisibility(View.GONE);
return;
}
PlaybackStateCompat state = mediaController.getPlaybackState();
MediaRouter.RouteInfo route = MediaRouter.getInstance(getContext()).getSelectedRoute();
CharSequence title = description.getTitle();
boolean hasTitle = !TextUtils.isEmpty(title);
CharSequence subtitle = description.getSubtitle();
boolean hasSubtitle = !TextUtils.isEmpty(subtitle);
boolean showTitle = false;
boolean showSubtitle = false;
if (route.getPresentationDisplayId() != MediaRouter.RouteInfo.PRESENTATION_DISPLAY_ID_NONE) {
// The user is currently casting screen.
titleView.setText(android.support.v7.mediarouter.R.string.mr_controller_casting_screen);
showTitle = true;
} else if (state == null || state.getState() == PlaybackStateCompat.STATE_NONE) {
// (Only exception is bluetooth where we don't show anything.)
if (!route.isDeviceTypeBluetooth()) {
titleView.setText(android.support.v7.mediarouter.R.string.mr_controller_no_media_selected);
showTitle = true;
}
} else if (!hasTitle && !hasSubtitle) {
titleView.setText(android.support.v7.mediarouter.R.string.mr_controller_no_info_available);
showTitle = true;
} else {
if (hasTitle) {
titleView.setText(title);
showTitle = true;
}
if (hasSubtitle) {
subtitleView.setText(subtitle);
showSubtitle = true;
}
}
if (showSubtitle) {
titleView.setSingleLine();
} else {
titleView.setMaxLines(2);
}
titleView.setVisibility(showTitle ? View.VISIBLE : View.GONE);
subtitleView.setVisibility(showSubtitle ? View.VISIBLE : View.GONE);
updateState();
if (rootView.getVisibility() != View.VISIBLE) {
artView.setVisibility(View.GONE);
rootView.setVisibility(View.VISIBLE);
}
if (fetchArtSubscription != null) {
fetchArtSubscription.unsubscribe();
}
fetchArtSubscription = Observable.fromCallable(() -> fetchArt(description)).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(result -> {
fetchArtSubscription = null;
if (artView == null) {
return;
}
if (result.first != null) {
if (!((Boolean) artView.getTag())) {
artView.setBackgroundColor(result.second);
}
artView.setImageBitmap(result.first);
artView.setVisibility(View.VISIBLE);
} else {
artView.setVisibility(View.GONE);
}
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
}
use of android.support.v4.media.MediaDescriptionCompat in project android-UniversalMusicPlayer by googlesamples.
the class CardPresenter method onBindViewHolder.
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
MediaDescriptionCompat description;
final CardViewHolder cardViewHolder = (CardViewHolder) viewHolder;
// Determine description and playing state of item based on instance type
cardViewHolder.setState(MediaItemViewHolder.STATE_NONE);
if (item instanceof MediaBrowserCompat.MediaItem) {
MediaBrowserCompat.MediaItem mediaItem = (MediaBrowserCompat.MediaItem) item;
LogHelper.d(TAG, "onBindViewHolder MediaItem: ", mediaItem.toString());
description = mediaItem.getDescription();
cardViewHolder.setState(MediaItemViewHolder.getMediaItemState(mContext, mediaItem));
} else if (item instanceof MediaSessionCompat.QueueItem) {
MediaSessionCompat.QueueItem queueItem = (MediaSessionCompat.QueueItem) item;
LogHelper.d(TAG, "onBindViewHolder QueueItem: ", queueItem.toString());
description = queueItem.getDescription();
if (QueueHelper.isQueueItemPlaying(mContext, queueItem)) {
cardViewHolder.setState(MediaItemViewHolder.getStateFromController(mContext));
}
} else {
throw new IllegalArgumentException("Object must be MediaItem or QueueItem, not " + item.getClass().getSimpleName());
}
cardViewHolder.setupCardView(mContext, description);
}
use of android.support.v4.media.MediaDescriptionCompat in project android-UniversalMusicPlayer by googlesamples.
the class MediaItemViewHolder method setupListView.
// Returns a view for use in media item list.
static View setupListView(Activity activity, View convertView, ViewGroup parent, MediaBrowserCompat.MediaItem item) {
if (sColorStateNotPlaying == null || sColorStatePlaying == null) {
initializeColorStateLists(activity);
}
MediaItemViewHolder holder;
Integer cachedState = STATE_INVALID;
if (convertView == null) {
convertView = LayoutInflater.from(activity).inflate(R.layout.media_list_item, parent, false);
holder = new MediaItemViewHolder();
holder.mImageView = (ImageView) convertView.findViewById(R.id.play_eq);
holder.mTitleView = (TextView) convertView.findViewById(R.id.title);
holder.mDescriptionView = (TextView) convertView.findViewById(R.id.description);
convertView.setTag(holder);
} else {
holder = (MediaItemViewHolder) convertView.getTag();
cachedState = (Integer) convertView.getTag(R.id.tag_mediaitem_state_cache);
}
MediaDescriptionCompat description = item.getDescription();
holder.mTitleView.setText(description.getTitle());
holder.mDescriptionView.setText(description.getSubtitle());
// If the state of convertView is different, we need to adapt the view to the
// new state.
int state = getMediaItemState(activity, item);
if (cachedState == null || cachedState != state) {
Drawable drawable = getDrawableByState(activity, state);
if (drawable != null) {
holder.mImageView.setImageDrawable(drawable);
holder.mImageView.setVisibility(View.VISIBLE);
} else {
holder.mImageView.setVisibility(View.GONE);
}
convertView.setTag(R.id.tag_mediaitem_state_cache, state);
}
return convertView;
}
use of android.support.v4.media.MediaDescriptionCompat in project AndroidAudioExample by SergeyVinyar.
the class MediaStyleHelper method from.
/**
* Build a notification using the information from the given media session. Makes heavy use
* of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
*
* @param context Context used to construct the notification.
* @param mediaSession Media session to get information.
* @return A pre-built notification with information from the given media session.
*/
static NotificationCompat.Builder from(Context context, MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mediaMetadata = controller.getMetadata();
MediaDescriptionCompat description = mediaMetadata.getDescription();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setContentTitle(description.getTitle()).setContentText(description.getSubtitle()).setSubText(description.getDescription()).setLargeIcon(description.getIconBitmap()).setContentIntent(controller.getSessionActivity()).setDeleteIntent(MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder;
}
Aggregations