Ejemplo n.º 1
0
        void LoadChildrenImpl(string parentId, Result result)
        {
            LogHelper.Debug(Tag, "OnLoadChildren: parentMediaId=", parentId);

            var mediaItems = new JavaList <MediaBrowser.MediaItem> ();

            if (MediaIDHelper.MediaIdRoot == parentId)
            {
                LogHelper.Debug(Tag, "OnLoadChildren.ROOT");
                mediaItems.Add(new MediaBrowser.MediaItem(
                                   new MediaDescription.Builder()
                                   .SetMediaId(MediaIDHelper.MediaIdMusicsByGenre)
                                   .SetTitle(GetString(Resource.String.browse_genres))
                                   .SetIconUri(Android.Net.Uri.Parse("android.resource://" +
                                                                     "com.example.android.mediabrowserservice/drawable/ic_by_genre"))
                                   .SetSubtitle(GetString(Resource.String.browse_genre_subtitle))
                                   .Build(), MediaItemFlags.Browsable
                                   ));
            }
            else if (MediaIDHelper.MediaIdMusicsByGenre == parentId)
            {
                LogHelper.Debug(Tag, "OnLoadChildren.GENRES");
                foreach (var genre in musicProvider.Genres)
                {
                    var item = new MediaBrowser.MediaItem(
                        new MediaDescription.Builder()
                        .SetMediaId(MediaIDHelper.CreateBrowseCategoryMediaID(MediaIDHelper.MediaIdMusicsByGenre, genre))
                        .SetTitle(genre)
                        .SetSubtitle(GetString(Resource.String.browse_musics_by_genre_subtitle, genre))
                        .Build(), MediaItemFlags.Browsable
                        );
                    mediaItems.Add(item);
                }
            }
            else if (parentId.StartsWith(MediaIDHelper.MediaIdMusicsByGenre))
            {
                var genre = MediaIDHelper.GetHierarchy(parentId) [1];
                LogHelper.Debug(Tag, "OnLoadChildren.SONGS_BY_GENRE  genre=", genre);
                foreach (var track in musicProvider.GetMusicsByGenre(genre))
                {
                    var hierarchyAwareMediaID = MediaIDHelper.CreateMediaID(
                        track.Description.MediaId, MediaIDHelper.MediaIdMusicsByGenre, genre);
                    var trackCopy = new MediaMetadata.Builder(track)
                                    .PutString(MediaMetadata.MetadataKeyMediaId, hierarchyAwareMediaID)
                                    .Build();
                    var bItem = new MediaBrowser.MediaItem(
                        trackCopy.Description, MediaItemFlags.Playable);
                    mediaItems.Add(bItem);
                }
            }
            else
            {
                LogHelper.Warn(Tag, "Skipping unmatched parentMediaId: ", parentId);
            }
            LogHelper.Debug(Tag, "OnLoadChildren sending ", mediaItems.Count,
                            " results for ", parentId);
            result.SendResult(mediaItems);
        }
        static List <MediaSession.QueueItem> ConvertToQueue(IEnumerable <MediaMetadata> tracks, params string[] categories)
        {
            var queue = new List <MediaSession.QueueItem>();
            int count = 0;

            foreach (var track in tracks)
            {
                string        hierarchyAwareMediaID = MediaIDHelper.CreateMediaID(track.Description.MediaId, categories);
                MediaMetadata trackCopy             = new MediaMetadata.Builder(track)
                                                      .PutString(MediaMetadata.MetadataKeyMediaId, hierarchyAwareMediaID)
                                                      .Build();

                var item = new MediaSession.QueueItem(trackCopy.Description, count++);
                queue.Add(item);
            }
            return(queue);
        }