Exemplo 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);
        }
Exemplo n.º 2
0
        public static List <MediaSession.QueueItem> GetPlayingQueue(string mediaId,
                                                                    MusicProvider musicProvider)
        {
            // extract the browsing hierarchy from the media ID:
            var hierarchy = MediaIDHelper.GetHierarchy(mediaId);

            if (hierarchy.Length != 2)
            {
                LogHelper.Error(Tag, "Could not build a playing queue for this mediaId: ", mediaId);
                return(null);
            }

            var categoryType  = hierarchy[0];
            var categoryValue = hierarchy[1];

            LogHelper.Debug(Tag, "Creating playing queue for ", categoryType, ",  ", categoryValue);

            IEnumerable <MediaMetadata> tracks = null;

            // This sample only supports genre and by_search category types.
            if (categoryType == MediaIDHelper.MediaIdMusicsByGenre)
            {
                tracks = musicProvider.GetMusicsByGenre(categoryValue);
            }
            else if (categoryType == MediaIDHelper.MediaIdMusicsBySearch)
            {
                tracks = musicProvider.SearchMusic(categoryValue);
            }

            if (tracks == null)
            {
                LogHelper.Error(Tag, "Unrecognized category type: ", categoryType, " for mediaId ", mediaId);
                return(null);
            }

            return(ConvertToQueue(tracks, hierarchy[0], hierarchy[1]));
        }