示例#1
0
        private async void pageRoot_Loaded_1(object sender, RoutedEventArgs e)
        {
            if (MediaControl.IsPlaying)
            {
                BG1.Begin();
            }

            if (Globalv.GlobalTopTracks.Count == 0)
            {
                progbar.Visibility = Visibility.Visible;
                bool success = false;
                try
                {
                    string resp = await Lastfm.chart_topTracks();

                    using (XmlReader rd = XmlReader.Create(new StringReader(resp)))
                    {
                        //for headliner
                        rd.ReadToFollowing("name");
                        GroupName = rd.ReadElementContentAsString();
                        rd.ReadToFollowing("playcount");
                        long pc = rd.ReadElementContentAsLong();
                        rd.ReadToFollowing("listeners");
                        long listeners = rd.ReadElementContentAsLong();
                        rd.ReadToFollowing("artist");
                        rd.ReadToDescendant("name");
                        string artist = rd.ReadElementContentAsString();
                        GroupDescription = "Artist: " + artist + "\nTrack heard over " + pc.ToString() + " times by " + listeners.ToString() + " listeners worldwide.";
                        Song s = new Song();
                        s.Artist = artist;
                        s.Title  = GroupName;
                        string resp2 = await Lastfm.track_getInfo(s);

                        using (XmlReader rd2 = XmlReader.Create(new StringReader(resp2)))
                        {
                            rd2.ReadToFollowing("album");
                            rd2.ReadToDescendant("image");
                            rd2.ReadToNextSibling("image");
                            rd2.ReadToNextSibling("image");

                            GroupImage = new BitmapImage(new Uri(rd2.ReadElementContentAsString(), UriKind.Absolute));
                        }
                        GNameTb.Text  = GroupName;
                        GImage.Source = GroupImage;
                        GDesc.Text    = GroupDescription;

                        //for other items
                        for (int i = 0; i < 19; i++)
                        {
                            //for headliner
                            Song s2 = new Song();
                            rd.ReadToFollowing("name");
                            s2.Title = rd.ReadElementContentAsString();
                            rd.ReadToFollowing("playcount");
                            long pclist = rd.ReadElementContentAsLong();
                            rd.ReadToFollowing("listeners");
                            long listenerslist = rd.ReadElementContentAsLong();
                            rd.ReadToFollowing("artist");
                            rd.ReadToDescendant("name");
                            s2.Artist  = rd.ReadElementContentAsString();
                            s2.content = "Artist: " + s2.Artist + "\nTrack heard over " + pclist.ToString() + " times by " + listenerslist.ToString() + " listeners worldwide.";
                            string resp22 = await Lastfm.track_getInfo(s2);

                            try
                            {
                                using (XmlReader rd2 = XmlReader.Create(new StringReader(resp22)))
                                {
                                    rd2.ReadToFollowing("album");
                                    rd2.ReadToFollowing("image");
                                    rd2.ReadToNextSibling("image");
                                    rd2.ReadToNextSibling("image");
                                    s2.image = new BitmapImage(new Uri(rd2.ReadElementContentAsString(), UriKind.Absolute));
                                }
                            }
                            catch (Exception) { }
                            TopTracks.Add(s2);
                        }
                        itemsGridView.ItemsSource = TopTracks;
                        Globalv.GlobalTopTracks   = TopTracks;
                    }
                    success = true;
                }
                catch (Exception)
                { success = false; }

                if (!success)
                {
                    MessageDialog m = new MessageDialog("This feature requires you to be connected to the internet. Connect to the internet and try again", "You're offline");
                    await m.ShowAsync();
                }
                progbar.Visibility = Visibility.Collapsed;
            }
            else
            {
                itemsGridView.ItemsSource = TopTracks;
            }
        }