List of usage examples for android.media MediaDescription getIconUri
public @Nullable Uri getIconUri()
From source file:org.opensilk.video.data.MediaDescriptionUtil.java
public static MediaDescription.Builder newBuilder(MediaDescription description) { MediaDescription.Builder bob = new MediaDescription.Builder().setIconUri(description.getIconUri()) .setMediaId(description.getMediaId()).setExtras(description.getExtras()) .setSubtitle(description.getSubtitle()).setTitle(description.getTitle()) .setDescription(description.getDescription()); if (VersionUtils.hasApi23()) { bob.setMediaUri(description.getMediaUri()); }//from w w w .jav a 2s . co m return bob; }
From source file:org.opensilk.video.data.VideosProviderClient.java
public boolean insertMedia(MediaBrowser.MediaItem mediaItem) { ContentValues cv = new ContentValues(10); MediaDescription description = mediaItem.getDescription(); MediaMetaExtras metaExtras = MediaMetaExtras.from(description.getExtras()); Uri mediaUri = MediaDescriptionUtil.getMediaUri(description); cv.put("_display_name", metaExtras.getMediaTitle()); String descriptionTitle = description.getTitle() != null ? description.getTitle().toString() : null; cv.put("_title", descriptionTitle); String descriptionSubtitle = description.getSubtitle() != null ? description.getSubtitle().toString() : null;/*from www. j a v a 2s .co m*/ cv.put("_subtitle", descriptionSubtitle); cv.put("parent_media_uri", metaExtras.getParentUri().toString()); cv.put("server_id", metaExtras.getServerId()); cv.put("media_category", metaExtras.getMediaType()); if (description.getIconUri() != null) { cv.put("artwork_uri", description.getIconUri().toString()); } cv.put("is_indexed", metaExtras.isIndexed() ? 1 : 0); //Not setting last_played or duration service does that if (metaExtras.isTvEpisode()) { tvdb().onInsertMedia(mediaItem, cv); } else if (metaExtras.isMovie()) { moviedb().onInsertMedia(mediaItem, cv); } try { int num = mResolver.update(mUris.media(), cv, "media_uri=?", new String[] { mediaUri.toString() }); if (num > 0) { Timber.d("Updated %d rows for %s", num, metaExtras.getMediaTitle()); return true; } cv.put("media_uri", mediaUri.toString()); cv.put("date_added", System.currentTimeMillis()); return mResolver.insert(mUris.media(), cv) != null; } catch (SQLiteException e) { Timber.w(e, "Failed updating %s values=%s", metaExtras.getMediaTitle(), cv.toString()); return false; } }
From source file:org.opensilk.video.playback.PlaybackService.java
void updateMetadata() { assertCreated();//ww w . ja va 2 s .c o m final Media media = mMediaPlayer.getMedia(); final MediaBrowser.MediaItem mediaItem = mDbClient.getMedia(media.getUri()); final MediaMetadata.Builder b = new MediaMetadata.Builder(); CharSequence title; Uri artworkUri = null; long duration; if (mediaItem != null) { MediaDescription description = mediaItem.getDescription(); title = description.getTitle(); b.putText(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title); b.putText(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE, description.getSubtitle()); if (description.getIconUri() != null) { b.putText(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, description.getIconUri().toString()); artworkUri = description.getIconUri(); } MediaMetaExtras metaExtras = MediaMetaExtras.from(description); b.putText(MediaMetadata.METADATA_KEY_TITLE, metaExtras.getMediaTitle()); duration = metaExtras.getDuration(); } else { title = media.getMeta(Media.Meta.Title); b.putText(MediaMetadata.METADATA_KEY_DISPLAY_TITLE, title); String artworkUrl = media.getMeta(Media.Meta.ArtworkURL); if (!StringUtils.isEmpty(artworkUrl)) { b.putText(MediaMetadata.METADATA_KEY_DISPLAY_ICON_URI, artworkUrl); artworkUri = Uri.parse(artworkUrl); } duration = mMediaPlayer.getLength(); } b.putLong(MediaMetadata.METADATA_KEY_DURATION, duration); if (artworkUri != null) { RequestOptions options = new RequestOptions().fitCenter(mContext); FutureTarget<Bitmap> futureTarget = Glide.with(mContext).asBitmap().apply(options).load(artworkUri) .submit(); try { Bitmap bitmap = futureTarget.get(5000, TimeUnit.MILLISECONDS); b.putBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON, bitmap); } catch (InterruptedException | ExecutionException | TimeoutException e) { //pass } } mMediaSession.setMetadata(b.build()); mMediaSession.setSessionActivity(makeActivityIntent(mediaItem)); }