/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property provides the collection of items to be displayed.</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { //this.DefaultViewModel["Items"] = e.Parameter; progbar.Visibility = Visibility.Visible; bool success = false; bool noReco = false; try { Song s = new Song(); s.Artist = Playlist.NowPlaying[0].Artist; s.Title = Playlist.NowPlaying[0].Title; string resp = await Lastfm.track_getSimilar(s); Globalv.RecommendedTracks.Clear(); using (XmlReader rd = XmlReader.Create(new StringReader(resp))) { /* Smart piece of code! pat pat*/ for (int i = 0; ; i++) { Song p = new Song(); rd.ReadToFollowing("track"); rd.ReadToDescendant("name"); p.Title = rd.ReadElementContentAsString(); rd.ReadToNextSibling("artist"); rd.ReadToDescendant("name"); p.Artist = rd.ReadElementContentAsString(); rd.ReadToFollowing("image"); rd.ReadToNextSibling("image"); rd.ReadToNextSibling("image"); p.image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(rd.ReadElementContentAsString(), UriKind.Absolute)); Globalv.RecommendedTracks.Add(p); success = true; } } } catch (InvalidOperationException) { noReco = true; } catch (Exception) { success = false; } //if success is false and noReco is true => no recommendations found! if (!success) { if (noReco) { MessageDialog m = new MessageDialog("Sorry we couldn't find any similar tracks. We'll try to fix it soon.", "Oops!"); await m.ShowAsync(); } else { 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(); } } else { itemGridView.ItemsSource = Globalv.RecommendedTracks; } progbar.Visibility = Visibility.Collapsed; }
async void pin_Tapped(object sender, TappedRoutedEventArgs e) { progbar.Visibility = Visibility.Visible; Pushpin pin = (Pushpin)sender; string resp = await Lastfm.geo_topTrack(pin.Text); Globalv.CountryTrends.Clear(); using (XmlReader rd = XmlReader.Create(new StringReader(resp))) { for (int i = 0; i < 12; i++) { Song s2 = new Song(); rd.ReadToFollowing("name"); s2.Title = rd.ReadElementContentAsString(); 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) { } Globalv.CountryTrends.Add(s2); } itemsGridView.ItemsSource = Globalv.CountryTrends; itemsGridView.UpdateLayout(); } progbar.Visibility = Visibility.Collapsed; }
public static async Task<string> track_getInfo(Song id3) { try { HttpClient cli = new HttpClient(); string get_track_info = @"http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=" + Globalv.lfm_api_key + @"&artist=" + id3.Artist + @"&track=" + id3.Title + @"&autocorrect=1"; HttpResponseMessage track_info = await cli.GetAsync(get_track_info); return await track_info.Content.ReadAsStringAsync(); } catch (Exception) { return null; } }
public static async Task<string> track_getSimilar(Song id3) { try { HttpClient cli = new HttpClient(); //Playlist.NowPlaying.Add() string get_track_reco = @"http://ws.audioscrobbler.com/2.0/?method=track.getsimilar&artist=" + id3.Artist + @"&track=" + id3.Title + @"&limit=14&api_key=" + Globalv.lfm_api_key; HttpResponseMessage reco = await cli.GetAsync(get_track_reco); return await reco.Content.ReadAsStringAsync(); } catch (Exception) { return null; } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property provides the group to be displayed.</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { 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; } }