public static MediaDescriptionCompat ToMediaDescription(this IMediaItem item) { var description = new MediaDescriptionCompat.Builder() .SetMediaId(item?.MediaId) .SetMediaUri(global::Android.Net.Uri.Parse(item?.MediaUri)) .SetTitle(item?.GetTitle()) .SetSubtitle(item?.GetContentTitle()) .SetDescription(item?.DisplayDescription) .SetExtras(item?.Extras as Bundle) .SetIconBitmap(item?.GetCover()) .SetIconUri(!string.IsNullOrEmpty(item?.DisplayIconUri) ? global::Android.Net.Uri.Parse(item?.DisplayIconUri) : null) .Build(); return(description); }
private MediaBrowserCompat.MediaItem CreateMediaItem(MediaMetadataCompat metadata) { // Since mediaMetadata fields are immutable, we need to create a copy, so we // can set a hierarchy-aware mediaID. We will need to know the media hierarchy // when we get a onPlayFromMusicID call, so we can create the proper queue based // on where the music was selected from (by artist, by genre, random, etc) var id = metadata.Description.MediaId; var playExtras = new Bundle(); playExtras.PutLong(MediaMetadataCompat.MetadataKeyDuration, metadata.GetLong(MediaMetadataCompat.MetadataKeyDuration)); var desc = new MediaDescriptionCompat.Builder() .SetMediaId(id) .SetTitle(metadata.GetString(MediaMetadataCompat.MetadataKeyTitle)) .SetSubtitle(metadata.GetString(MediaMetadataCompat.MetadataKeyArtist)) .SetExtras(playExtras) .Build(); return(new MediaBrowserCompat.MediaItem(desc, MediaBrowserCompat.MediaItem.FlagPlayable)); }