Example usage for android.media MediaMetadata METADATA_KEY_DISPLAY_ICON

List of usage examples for android.media MediaMetadata METADATA_KEY_DISPLAY_ICON

Introduction

In this page you can find the example usage for android.media MediaMetadata METADATA_KEY_DISPLAY_ICON.

Prototype

String METADATA_KEY_DISPLAY_ICON

To view the source code for android.media MediaMetadata METADATA_KEY_DISPLAY_ICON.

Click Source Link

Document

An icon or thumbnail that is suitable for display to the user.

Usage

From source file:org.opensilk.video.playback.PlaybackService.java

void updateMetadata() {
    assertCreated();//from  ww  w.  j  a  va 2s  .  co  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));
}