List of usage examples for android.support.v4.media MediaDescriptionCompat getIconUri
@Nullable
public Uri getIconUri()
From source file:rocks.stalin.android.app.ui.MediaItemViewHolder.java
static View setupListView(Activity activity, View convertView, ViewGroup parent, MediaBrowserCompat.MediaItem item) { if (sColorStateNotPlaying == null || sColorStatePlaying == null) { initializeColorStateLists(activity); }/* w w w . j a va 2s. c o m*/ 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 (item.isBrowsable() && description.getIconUri() != null) { holder.mImageView.setImageURI(description.getIconUri()); holder.mImageView.setVisibility(View.VISIBLE); return convertView; } // 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; }
From source file:nuclei.media.QueueItem.java
public void setIcon(Bitmap bitmap) { MediaDescriptionCompat desc = mQueueItem.getDescription(); desc = new MediaDescriptionCompat.Builder().setTitle(desc.getTitle()).setDescription(desc.getDescription()) .setMediaId(desc.getMediaId()).setMediaUri(desc.getMediaUri()).setIconUri(desc.getIconUri()) .setIconBitmap(bitmap).setExtras(desc.getExtras()).setSubtitle(desc.getSubtitle()).build(); mQueueItem = new MediaSessionCompat.QueueItem(desc, mQueueItem.getQueueId()); }
From source file:androidx.media.MediaUtils2.java
/** * Creates a {@link MediaMetadata2} from the {@link MediaDescriptionCompat}. * * @param descCompat A {@link MediaDescriptionCompat} object. * @return The newly created {@link MediaMetadata2} object. */// w w w . ja v a 2 s . c om static MediaMetadata2 createMediaMetadata2(MediaDescriptionCompat descCompat) { if (descCompat == null) { return null; } MediaMetadata2.Builder metadata2Builder = new MediaMetadata2.Builder(); metadata2Builder.putString(METADATA_KEY_MEDIA_ID, descCompat.getMediaId()); CharSequence title = descCompat.getTitle(); if (title != null) { metadata2Builder.putText(METADATA_KEY_DISPLAY_TITLE, title); } CharSequence description = descCompat.getDescription(); if (description != null) { metadata2Builder.putText(METADATA_KEY_DISPLAY_DESCRIPTION, descCompat.getDescription()); } CharSequence subtitle = descCompat.getSubtitle(); if (subtitle != null) { metadata2Builder.putText(METADATA_KEY_DISPLAY_SUBTITLE, subtitle); } Bitmap icon = descCompat.getIconBitmap(); if (icon != null) { metadata2Builder.putBitmap(METADATA_KEY_DISPLAY_ICON, icon); } Uri iconUri = descCompat.getIconUri(); if (iconUri != null) { metadata2Builder.putText(METADATA_KEY_DISPLAY_ICON_URI, iconUri.toString()); } Bundle bundle = descCompat.getExtras(); if (bundle != null) { metadata2Builder.setExtras(descCompat.getExtras()); } Uri mediaUri = descCompat.getMediaUri(); if (mediaUri != null) { metadata2Builder.putText(METADATA_KEY_MEDIA_URI, mediaUri.toString()); } return metadata2Builder.build(); }
From source file:cat.terrones.devops.radiofx.ui.FullScreenPlayerActivity.java
private void fetchImageAsync(@NonNull MediaDescriptionCompat description) { if (description.getIconUri() == null) { return;/*from ww w. j a va 2 s .com*/ } String artUrl = description.getIconUri().toString(); mCurrentArtUrl = artUrl; AlbumArtCache cache = AlbumArtCache.getInstance(); Bitmap art = cache.getBigImage(artUrl); if (art == null) { art = description.getIconBitmap(); } if (art != null) { // if we have the art cached or from the MediaDescription, use it: mBackgroundImage.setImageBitmap(art); } else { // otherwise, fetch a high res version and update: cache.fetch(artUrl, new AlbumArtCache.FetchListener() { @Override public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) { // sanity check, in case a new fetch request has been done while // the previous hasn't yet returned: if (artUrl.equals(mCurrentArtUrl)) { mBackgroundImage.setImageBitmap(bitmap); } } }); } }
From source file:com.torrenttunes.android.ui.FullScreenPlayerActivity.java
private void fetchImageAsync(MediaDescriptionCompat description) { String artUrl = description.getIconUri().toString(); mCurrentArtUrl = artUrl;//from w ww . ja v a2s . c o m AlbumArtCache cache = AlbumArtCache.getInstance(); Bitmap art = cache.getBigImage(artUrl); if (art == null) { art = description.getIconBitmap(); } if (art != null && !art.isRecycled()) { // if we have the art cached or from the MediaDescription, use it: mBackgroundImage.setImageBitmap(art); } else { // otherwise, fetch a high res version and update: cache.fetch(artUrl, new AlbumArtCache.FetchListener() { @Override public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) { // sanity check, in case a new fetch request has been done while // the previous hasn't yet returned: if (!bitmap.isRecycled() && artUrl.equals(mCurrentArtUrl)) { mBackgroundImage.setImageBitmap(bitmap); } } }); } }
From source file:dk.glutter.android.knr.ui.FullScreenPlayerActivity.java
private void fetchImageAsync(@NonNull MediaDescriptionCompat description) { if (description.getIconUri() == null) { return;/* w w w . ja va2 s . c o m*/ } String artUrl = description.getIconUri().toString(); mCurrentArtUrl = artUrl; AlbumArtCache cache = AlbumArtCache.getInstance(); Bitmap art = cache.getBigImage(artUrl); if (art == null) { art = description.getIconBitmap(); } if (art != null) { // if we have the art cached or from the MediaDescription, use it: mBackgroundImage.setImageBitmap(art); } else { // otherwise, fetch a high res version and update: cache.fetch(artUrl, new AlbumArtCache.FetchListener() { @Override public void onError(String artUrl, Exception e) { Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.bg); mBackgroundImage.setImageBitmap(image); } @Override public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) { // sanity check, in case a new fetch request has been done while // the previous hasn't yet returned: if (artUrl.equals(mCurrentArtUrl)) { mBackgroundImage.setImageBitmap(bitmap); } } }); } }
From source file:com.murati.oszk.audiobook.ui.FullScreenPlayerActivity.java
private void fetchImageAsync(@NonNull MediaDescriptionCompat description) { if (description.getIconUri() == null) { return;/*w ww. ja va 2 s . c om*/ } mCurrentArtUrl = description.getIconUri().toString(); //TODO: create fallback book-title GlideApp.with(this).load(mCurrentArtUrl).override(Target.SIZE_ORIGINAL).into(mBackgroundImage); }
From source file:com.example.android.supportv4.media.MediaNotificationManager.java
private Notification createNotification() { Log.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }/* www . jav a 2 s.c o m*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousIntent); } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { // This sample assumes the iconUri will be a valid URL formatted String, but // it can actually be any valid Android Uri formatted String. // async fetch the album art icon String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; // use a placeholder art while the remote art is being downloaded art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } notificationBuilder.setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setUsesChronometer(true) .setContentIntent(createContentIntent()).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); setNotificationPlaybackState(notificationBuilder); if (fetchArtUrl != null) { fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); } return notificationBuilder.build(); }
From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java
private void fetchImageAsync(@NonNull final MediaDescriptionCompat description) { if (description.getIconUri() == null) { com.appdevper.mediaplayer.util.Utils.downloadBitmap(getResources(), description.getMediaId(), mBackgroundImage);/*from www . j a v a 2s . c om*/ return; } String artUrl = description.getIconUri().toString(); mCurrentArtUrl = artUrl; AlbumArtCache cache = AlbumArtCache.getInstance(); Bitmap art = cache.getBigImage(artUrl); if (art == null) { art = description.getIconBitmap(); } if (art != null) { // if we have the art cached or from the MediaDescription, use it: mBackgroundImage.setImageBitmap(art); } else { // otherwise, fetch a high res version and update: cache.fetch(artUrl, new AlbumArtCache.FetchListener() { @Override public void onFetched(String artUrl, Bitmap bitmap, Bitmap icon) { if (artUrl.equals(mCurrentArtUrl)) { mBackgroundImage.setImageBitmap(bitmap); } } @Override public void onError(String artUrl, Exception e) { com.appdevper.mediaplayer.util.Utils.downloadBitmap(getResources(), description.getMediaId(), mBackgroundImage); } }); } }
From source file:com.example.android.mediabrowserservice.MediaNotificationManager.java
private Notification createNotification() { LogHelper.d(TAG, "updateNotificationMetadata. mMetadata=" + mMetadata); if (mMetadata == null || mPlaybackState == null) { return null; }/*from www.ja va 2s . co m*/ NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService); int playPauseButtonPosition = 0; // If skip to previous action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_previous_white_24dp, mService.getString(R.string.label_previous), mPreviousIntent); // If there is a "skip to previous" button, the play/pause button will // be the second one. We need to keep track of it, because the MediaStyle notification // requires to specify the index of the buttons (actions) that should be visible // when in compact view. playPauseButtonPosition = 1; } addPlayPauseAction(notificationBuilder); // If skip to next action is enabled if ((mPlaybackState.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) { notificationBuilder.addAction(R.drawable.ic_skip_next_white_24dp, mService.getString(R.string.label_next), mNextIntent); } MediaDescriptionCompat description = mMetadata.getDescription(); String fetchArtUrl = null; Bitmap art = null; if (description.getIconUri() != null) { // This sample assumes the iconUri will be a valid URL formatted String, but // it can actually be any valid Android Uri formatted String. // async fetch the album art icon String artUrl = description.getIconUri().toString(); art = AlbumArtCache.getInstance().getBigImage(artUrl); if (art == null) { fetchArtUrl = artUrl; // use a placeholder art while the remote art is being downloaded art = BitmapFactory.decodeResource(mService.getResources(), R.drawable.ic_default_art); } } notificationBuilder .setStyle(new NotificationCompat.MediaStyle() .setShowActionsInCompactView(new int[] { playPauseButtonPosition }) // show only play/pause in compact view .setMediaSession(mSessionToken)) .setColor(mNotificationColor).setSmallIcon(R.drawable.ic_notification) .setVisibility(Notification.VISIBILITY_PUBLIC).setUsesChronometer(true) .setContentIntent(createContentIntent()).setContentTitle(description.getTitle()) .setContentText(description.getSubtitle()).setLargeIcon(art); setNotificationPlaybackState(notificationBuilder); if (fetchArtUrl != null) { fetchBitmapFromURLAsync(fetchArtUrl, notificationBuilder); } return notificationBuilder.build(); }