Exemplo n.º 1
0
        public void FillPlaylist(SonosPlayer pl)
        {
            IList <PlaylistItem> list = new List <PlaylistItem>();

            try
            {
                var xml = pl.GetPlaylistWithTotalNumbers(NumberReturned, 0);
                if (xml[0] == null || xml[0].Length == 0)
                {
                    xml = pl.GetPlaylistWithTotalNumbers(NumberReturned, 0, 500);
                }
                if (xml[0] == null || xml[0].Length == 0)
                {
                    SonosHelper.ServerErrorsAdd("Playlist:FillPlaylist:Block1", new Exception("Zurückgelieferte Liste Leer"));
                }

                if (xml[1] != null)
                {
                    TotalMatches = Convert.ToInt16(xml[1]);
                    list         = ParseSonosXML(xml[0]);
                }
            }
            catch (Exception ex)
            {
                SonosHelper.ServerErrorsAdd("Playlist:FillPlaylist:Block1", ex);
            }

            //Eintrag in der Liste vorhanden
            if (TotalMatches == 0 && list.Count == 0)
            {
                PlayListItems.Add(new PlaylistItem()
                {
                    Album = "Leer", Artist = "Leer", Title = "Leer"
                });
                return;
            }
            try
            {
                if (list.Count > 0)
                {
                    PlayListItems.AddRange(list);
                    NumberReturned = Convert.ToUInt16(PlayListItems.Count);
                }

                if (PlayListItems.Count < TotalMatches)
                {
                    FillPlaylist(pl);
                }
            }
            catch (Exception ex)
            {
                SonosHelper.ServerErrorsAdd("Playlist:FillPlaylist:Block2", ex);
            }
        }