Beispiel #1
0
        public Dictionary <string, List <MediaItem> > GetSongsByArtist()
        {
            Dictionary <string, List <MediaItem> > artistSongs = new Dictionary <string, List <MediaItem> >();

            try
            {
                MusicQuery musicQuery   = new MusicQuery();
                var        artistSongs1 = musicQuery.queryForSongs();

                MPMediaQuery            mediaQuery    = MPMediaQuery.ArtistsQuery;
                MPMediaItemCollection[] songsByArtist = mediaQuery.Collections;
                List <MediaItem>        songs;
                foreach (MPMediaItemCollection artist in songsByArtist)
                {
                    MPMediaItem[] songItems  = artist.Items;
                    string        artistName = "";
                    songs = new List <MediaItem>();
                    foreach (MPMediaItem songItem in songItems)
                    {
                        // Create a new song type and add the info from this song to it
                        MediaItem song = new MediaItem();
                        try
                        {
                            if (artistName == "")
                            {
                                artistName = songItem.Artist;
                            }
                            SetMediaItem(ref song, songItem);
                            songs.Add(song);
                        }
                        catch (Exception ex)
                        {
                            Messages.Add(GetExceptionDetail(ex));
                        }
                    }

                    if (!artistSongs.ContainsKey(artistName))
                    {
                        artistSongs.Add(artistName, songs);
                    }
                    else
                    {
                        List <MediaItem> temp = null;
                        artistSongs.TryGetValue(artistName, out temp);
                        if (temp != null)
                        {
                            temp.AddRange(songs);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Messages.Add(GetExceptionDetail(ex));
                _ = ex;
            }

            return(artistSongs);
        }
Beispiel #2
0
        // Get the songs from the music library
        public static void querySongs()
        {
            MusicQuery musicQuery = new MusicQuery();

            artistSongs = musicQuery.queryForSongs();
            artistCount = artistSongs.Count;

            var artists = artistSongs.Values;

            songCount = 0;
            foreach (List <Song> songs in artists)
            {
                songCount += songs.Count;
            }

            searchSongCount   = 0;
            searchArtistCount = 0;
        }