List of usage examples for android.support.v4.media MediaDescriptionCompat getMediaId
@Nullable
public String getMediaId()
From source file:nuclei.media.MediaPlayerController.java
@Nullable public static String getMediaId(MediaMetadataCompat metadataCompat) { MediaDescriptionCompat descriptionCompat = metadataCompat == null ? null : metadataCompat.getDescription(); if (descriptionCompat != null) return descriptionCompat.getMediaId(); return null;/*w w w. ja va 2 s . c o m*/ }
From source file:com.scooter1556.sms.android.utils.MediaUtils.java
public static MediaMetadata getMediaMetadataFromMediaDescription(MediaDescriptionCompat description) { MediaMetadata metadata = new MediaMetadata(getMediaTypeFromID(description.getMediaId())); // Get Media Element ID from Media ID List<String> mediaID = parseMediaId(description.getMediaId()); if (mediaID.size() <= 1) { return null; }// ww w .ja va 2s . c o m UUID id = UUID.fromString(mediaID.get(1)); if (description.getTitle() != null) { metadata.putString(MediaMetadata.KEY_TITLE, description.getTitle().toString()); } if (description.getSubtitle() != null) { metadata.putString(MediaMetadata.KEY_SUBTITLE, description.getSubtitle().toString()); } metadata.putInt(MediaMetadata.KEY_TRACK_NUMBER, description.getExtras().getShort("TrackNumber")); metadata.putInt(MediaMetadata.KEY_DISC_NUMBER, description.getExtras().getShort("DiscNumber")); if (RESTService.getInstance().getAddress() != null) { metadata.addImage( new WebImage(Uri.parse(RESTService.getInstance().getAddress() + "/image/" + id + "/cover"))); metadata.addImage( new WebImage(Uri.parse(RESTService.getInstance().getAddress() + "/image/" + id + "/fanart"))); } return metadata; }
From source file:com.murati.oszk.audiobook.ui.MediaItemViewHolder.java
static View setupListView(final Activity activity, View convertView, final ViewGroup parent, MediaBrowserCompat.MediaItem item) { if (sColorStateNotPlaying == null || sColorStatePlaying == null) initializeColorStateLists(activity); // Create holder and cache-state MediaDescriptionCompat description = item.getDescription(); final MediaItemViewHolder holder; Integer cachedState = STATE_INVALID; // Inflate new holder for the basic types: holder = new MediaItemViewHolder(); //TODO: optimize inflators if (MediaIDHelper.isItemHeader(description.getMediaId())) { // EBook header convertView = LayoutInflater.from(activity).inflate(R.layout.fragment_list_header, parent, false); } else if (MediaIDHelper.isEBookHeader(description.getMediaId())) { // EBook header convertView = LayoutInflater.from(activity).inflate(R.layout.fragment_ebook_header, parent, false); } else if (MediaIDHelper.isBrowseable(description.getMediaId()) && (MediaIDHelper.isEBook(description.getMediaId())) || MediaIDHelper.MEDIA_ID_BY_QUEUE.equals(description.getMediaId())) { // EBOOK Card // It is an e-book, so let's inflate with the e-book template convertView = LayoutInflater.from(activity).inflate(R.layout.fragment_ebook_item, parent, false); } else {//from w w w. j a v a 2 s . c o m // Everything else convertView = LayoutInflater.from(activity).inflate(R.layout.fragment_list_item, parent, false); } convertView.setTag(holder); //Lookup the standard fields 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); // Set values if (holder.mTitleView != null) { holder.mTitleView.setText(description.getTitle()); } if (holder.mDescriptionView != null) { holder.mDescriptionView.setText(description.getSubtitle()); } // Load images if (holder.mImageView != null) { // If the state of convertView is different, we need to adapt it int state = getMediaItemState(activity, item); if (cachedState == null || cachedState != state) { // Split case by browsable or by playable if (MediaIDHelper.isBrowseable(description.getMediaId()) || MediaIDHelper.isEBookHeader(description.getMediaId())) { // Browsable container represented by its image Uri imageUri = item.getDescription().getIconUri(); GlideApp.with(activity).load(imageUri).override(Target.SIZE_ORIGINAL) .fallback(R.drawable.default_book_cover).error(R.drawable.default_book_cover). /*listener(new RequestListener<Drawable>() { @Override public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { return false; } @Override public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { return false; } }).*/ into(holder.mImageView); // In addition to being browsable add quick-controls too if (MediaIDHelper.isEBook(description.getMediaId())) { holder.mDownloadButton = (Button) convertView.findViewById(R.id.card_download); if (holder.mDownloadButton != null) { holder.mDownloadButton.setTag(description.getMediaId()); holder.mDownloadButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { OfflineBookService.downloadWithActivity((String) v.getTag(), activity); } }); } holder.mFavoriteButton = (ImageView) convertView.findViewById(R.id.card_favorite); if (holder.mFavoriteButton != null) { holder.mFavoriteButton .setImageResource(FavoritesHelper.getFavoriteIcon(description.getMediaId())); holder.mFavoriteButton.setTag(description.getMediaId()); holder.mFavoriteButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ((ImageView) v).setImageResource( FavoritesHelper.toggleFavoriteWithText((String) v.getTag(), activity)); } }); } //holder.mOpenButton = (Button) convertView.findViewById(R.id.card_open); if (holder.mOpenButton != null) { //TODO: solve event listener } } } else { // Playable item represented by its state Drawable drawable = getDrawableByState(activity, state); if (drawable != null) holder.mImageView.setImageDrawable(drawable); //holder.mImageView.setImageTintMode(PorterDuff.Mode.SRC_IN); //If offline and not available /*if (!NetworkHelper.isOnline(parent.getContext())) { String source = OfflineBookService.getTrackSource( MusicProvider.getTrack(description.getMediaId())); holder.mTitleView.setTextColor(Color.CYAN); }*/ } holder.mImageView.setVisibility(View.VISIBLE); convertView.setTag(R.id.tag_mediaitem_state_cache, state); } } return convertView; }
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 ww . j av a 2 s . co m 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: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:nuclei.media.MediaPlayerController.java
@Override public void start() { if (mMediaId == null) return;/* w w w .j a va2 s . c o m*/ if (mMediaControls != null) { if (mCallbacks != null) { mCallbacks.onLoading(this); } String currentMediaId = null; MediaMetadataCompat metadataCompat = mMediaControls.getMetadata(); if (metadataCompat != null) { MediaDescriptionCompat descriptionCompat = metadataCompat.getDescription(); if (descriptionCompat != null) { currentMediaId = descriptionCompat.getMediaId(); } } final String id = mMediaId.toString(); if (mCallbacks != null && mCallbacks.onPlay(currentMediaId, id, this, mMediaControls.getTransportControls())) return; if (mCallbacks != null) mCallbacks.onPlaying(this); if (currentMediaId != null && currentMediaId.equals(id) && mMediaControls.getPlaybackState().getState() == PlaybackStateCompat.STATE_PAUSED) { mMediaControls.getTransportControls().play(); } else { mMediaControls.getTransportControls().playFromMediaId(id, null); } } else { mStartWhenReady = true; } }
From source file:nuclei.media.MediaNotificationManager.java
private PendingIntent createContentIntent(MediaDescriptionCompat description) { try {//from w w w . j a v a2 s .co m MediaId id = MediaProvider.getInstance().getMediaId(description.getMediaId()); Intent openUI = new Intent(mService, id.type == MediaId.TYPE_AUDIO ? Configuration.AUDIO_ACTIVITY : Configuration.VIDEO_ACTIVITY); openUI.putExtra(MediaService.MEDIA_ID, description.getMediaId()); openUI.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); return PendingIntent.getActivity(mService, REQUEST_CODE, openUI, PendingIntent.FLAG_CANCEL_CURRENT); } catch (Exception err) { throw new RuntimeException(err); } }
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);/* ww w . ja v a 2 s . com*/ 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.scooter1556.sms.android.presenter.MediaDescriptionPresenter.java
@Override public void onBindViewHolder(ViewHolder viewHolder, Object item) { MediaDescriptionCompat description = (MediaDescriptionCompat) item; if (description == null) { return;/* ww w .ja v a 2 s. c o m*/ } ImageCardView cardView = (ImageCardView) viewHolder.view; // Get title cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT); cardView.setMainImageScaleType(ImageView.ScaleType.CENTER); cardView.setTitleText(description.getTitle()); cardView.setContentText(description.getSubtitle()); // Get default icon Drawable icon; switch (MediaUtils.getMediaTypeFromID(description.getMediaId())) { case MediaElement.MediaElementType.AUDIO: icon = defaultAudioIcon; break; case MediaElement.MediaElementType.VIDEO: icon = defaultVideoIcon; break; default: icon = defaultAudioIcon; break; } List<String> id = MediaUtils.parseMediaId((description.getMediaId())); if (id.size() > 1) { // Set image RequestOptions options = new RequestOptions().error(icon); Glide.with(viewHolder.view.getContext()).asBitmap() .load(RESTService.getInstance().getConnection().getUrl() + "/image/" + id.get(1) + "/cover?scale=" + CARD_HEIGHT) .apply(options).into(cardView.getMainImageView()); } }
From source file:com.scooter1556.sms.android.playback.QueueManager.java
public void addToQueue(MediaDescriptionCompat description, int index) { if (description.getMediaId() == null) { return;//from ww w .j a v a 2 s.c o m } updateQueue(description.getMediaId(), index); }