示例#1
0
        async void ItemListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // Invalidate the view state when logical page navigation is in effect, as a change
            // in selection may cause a corresponding change in the current logical page.  When
            // an item is selected this has the effect of changing from displaying the item list
            // to showing the selected item's details.  When the selection is cleared this has the
            // opposite effect.
            if (this.UsingLogicalPageNavigation())
            {
                this.InvalidateVisualState();
            }

            progbar.Visibility = Visibility.Visible;
            Artist ar   = (Artist)itemListView.SelectedItem;
            string resp = await Lastfm.artist_getInfo(ar.name);

            using (XmlReader rd = XmlReader.Create(new StringReader(resp)))
            {
                rd.ReadToFollowing("summary");
                string content = rd.ReadElementContentAsString();
                rd.ReadToFollowing("content");
                content = String.Concat(content, rd.ReadElementContentAsString());

                ArtistContentTb.Text = HtmlUtilities.ConvertToText(content);
            }
            progbar.Visibility = Visibility.Collapsed;
        }
示例#2
0
        private async void Collection_Click_1(object sender, RoutedEventArgs e)
        {
            if (EnsureUnsnapped())
            {
                FileOpenPicker pkr = new FileOpenPicker();
                pkr.ViewMode = PickerViewMode.List;
                pkr.SuggestedStartLocation = PickerLocationId.MusicLibrary;
                pkr.FileTypeFilter.Add(".mp3");

                StorageFile file = await pkr.PickSingleFileAsync();

                if (null != file)
                {
                    var strm = await file.OpenAsync(FileAccessMode.Read);

                    Playlist.NowPlaying.Clear();
                    App.GlobalAudioElement.AudioCategory = Windows.UI.Xaml.Media.AudioCategory.BackgroundCapableMedia;
                    //mediaPlayer.SetSource(strm, file.ContentType);
                    App.GlobalAudioElement.SetSource(strm, file.ContentType);
                    App.GlobalAudioElement.Play();
                    //timelineSlider.Maximum = App.GlobalAudioElement.NaturalDuration.TimeSpan.TotalMilliseconds;
                    isScrobbledOnce = false;

                    MediaControl.IsPlaying = true;
                    BG1.Begin();
                    //PlayPauseBtn.Content = "";

                    id3 = await file.Properties.GetMusicPropertiesAsync();

                    SongTitle.Text          = id3.Title;
                    Artist.Text             = id3.Artist;
                    MediaControl.ArtistName = id3.Artist;
                    MediaControl.TrackName  = id3.Title;
                    Playlist.NowPlaying.Add(id3);
                    Lastfm.track_updateNowPlaying(id3);

                    string xmlinfo = await Lastfm.track_getInfo(id3);

                    string artistinfo = await Lastfm.artist_getInfo(id3.Artist);

                    try
                    {
                        using (XmlReader rd = XmlReader.Create(new StringReader(xmlinfo)))
                        {
                            rd.ReadToFollowing("name");
                            //TitleInfoTbx.Text = rd.ReadElementContentAsString();
                            rd.ReadToFollowing("artist");
                            rd.ReadToDescendant("name");
                            //SubtitleInfoTbx.Text = rd.ReadElementContentAsString();
                        }

                        Uri src;
                        using (XmlReader rd = XmlReader.Create(new StringReader(xmlinfo)))
                        {
                            rd.ReadToFollowing("image");
                            rd.ReadToNextSibling("image");
                            rd.ReadToNextSibling("image");
                            src = new Uri(rd.ReadElementContentAsString(), UriKind.Absolute);
                            AlbumArtHolder.Source = new BitmapImage(src);
                        }
                        using (XmlReader rd = XmlReader.Create(new StringReader(xmlinfo)))
                        {
                            rd.ReadToFollowing("wiki");
                            rd.ReadToDescendant("summary");
                            string text = rd.ReadElementContentAsString();

                            SummaryInfoTbx.Text = HtmlUtilities.ConvertToText(text);
                        }
                    }
                    catch (Exception)
                    {
                        try
                        {
                            using (XmlReader rd = XmlReader.Create(new StringReader(artistinfo)))
                            {
                                rd.ReadToFollowing("image");
                                rd.ReadToNextSibling("image");
                                rd.ReadToNextSibling("image");
                                Uri src = new Uri(rd.ReadElementContentAsString(), UriKind.Absolute);
                                AlbumArtHolder.Source = new BitmapImage(src);
                                MediaControl.AlbumArt = src;
                            }
                        }
                        catch (Exception)
                        {
                            AlbumArtHolder.Source = null;
                        }
                    }
                    //prepare for scrobble
                    TimelineMarker tlm = new TimelineMarker();
                    tlm.Time = new System.TimeSpan(0, 0, (int)id3.Duration.TotalSeconds / 2);
                    App.GlobalAudioElement.Markers.Clear();
                    App.GlobalAudioElement.Markers.Add(tlm);
                    if (id3.Duration > new System.TimeSpan(0, 0, 30))
                    {
                        await Lastfm.track_scrobble(id3);

                        isScrobbledOnce = true;

                        //App.GlobalAudioElement.MarkerReached += mediaPlayer_MarkerReached_scrobble; //scrobble
                    }
                }
                else
                {
                    return;
                }
            }
        }