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(); } Song s = (Song)itemListView.SelectedItem; string resp = await Lastfm.track_getInfo(s); try { using (XmlReader rd = XmlReader.Create(new StringReader(resp))) { rd.ReadToFollowing("summary"); string content = rd.ReadElementContentAsString(); rd.ReadToFollowing("content"); content = String.Concat(content, rd.ReadElementContentAsString()); TrackContentTb.Text = HtmlUtilities.ConvertToText(content); } } catch (Exception) { TrackContentTb.Text = "Additional information is currently unavailable."; } }
private async void Ban_Click_1(object sender, RoutedEventArgs e) { if (MediaControl.IsPlaying) { await Lastfm.track_love(id3); } }
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; }
async void pin_Tapped(object sender, TappedRoutedEventArgs e) { progbar.Visibility = Visibility.Visible; Pushpin pin = (Pushpin)sender; string resp = await Lastfm.geo_topTrack(pin.Text); SubHeaderTb.Text = "Current trends in " + pin.Text; Globalv.CountryTrends.Clear(); itemsGridView.ItemsSource = null; 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; }
private async void pageRoot_Loaded_1(object sender, RoutedEventArgs e) { if (MediaControl.IsPlaying) { BG1.Begin(); } if (Security._vault.RetrieveAll().Count == 0) { Globalv.session_key = null; } else { PasswordCredential rt = Security._vault.Retrieve("Session Key", "user"); rt.RetrievePassword(); Globalv.session_key = rt.Password; } if (Globalv.session_key == null) { progbar.Visibility = Visibility.Visible; String lfmURL = "https://www.last.fm/api/auth/?api_key=" + Globalv.lfm_api_key + "&cb=" + EndUri; System.Uri StartUri = new Uri(lfmURL); WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync( WebAuthenticationOptions.None, StartUri, EndUri); if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { //get and save lfm session key string[] responseData = WebAuthenticationResult.ResponseData.ToString().Split('?'); string token = responseData[1].Substring(6); HttpClient cli = new HttpClient(); string getsk_sig = "api_key" + Globalv.lfm_api_key + "methodauth.getSessiontoken" + token + "0e6e780c3cfa3faedf0c58d5aa6de92f"; HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm("MD5"); CryptographicHash objHash = objAlgProv.CreateHash(); IBuffer buffSig = CryptographicBuffer.ConvertStringToBinary(getsk_sig, BinaryStringEncoding.Utf8); objHash.Append(buffSig); IBuffer buffSighash = objHash.GetValueAndReset(); string api_sig = CryptographicBuffer.EncodeToHexString(buffSighash); string get_sk = @"http://ws.audioscrobbler.com/2.0/?method=auth.getSession&api_key=" + Globalv.lfm_api_key + "&api_sig=" + api_sig + "&token=" + token; HttpResponseMessage r = await cli.GetAsync(get_sk); string xml_resp = await r.Content.ReadAsStringAsync(); using (XmlReader rd = XmlReader.Create(new StringReader(xml_resp))) { rd.ReadToFollowing("key"); Globalv.session_key = rd.ReadElementContentAsString(); var c = new PasswordCredential("Session Key", "user", Globalv.session_key); Mu3.Security._vault.Add(c); /* * PasswordCredential rt = Security._vault.Retrieve("Session Key", "user"); * rt.RetrievePassword(); * MessageDialog m = new MessageDialog(rt.Password); * await m.ShowAsync(); */ } //MessageDialog m1 = new MessageDialog(Globalv.session_key); //await m1.ShowAsync(); } else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) { MessageDialog m = new MessageDialog("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString()); await m.ShowAsync(); } else { MessageDialog m = new MessageDialog("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString()); await m.ShowAsync(); } } string resp = await Lastfm.user_getRecommendedArtists(); Globalv.RecommendedArtists.Clear(); bool success = false; try { using (XmlReader rd = XmlReader.Create(new StringReader(resp))) { rd.ReadToFollowing("recommendations"); rd.MoveToAttribute("perPage"); int size = 34; for (int i = 0; i < size; i++) { Artist ar = new Artist(); //rd.ReadToFollowing("artist"); rd.ReadToFollowing("name"); ar.name = rd.ReadElementContentAsString(); rd.ReadToNextSibling("mbid"); ar.mbid = rd.ReadElementContentAsString(); rd.ReadToNextSibling("image"); rd.ReadToNextSibling("image"); rd.ReadToNextSibling("image"); ar.image = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri(rd.ReadElementContentAsString(), UriKind.Absolute)); Globalv.RecommendedArtists.Add(ar); } List <Artist> dps = Globalv.RecommendedArtists.Distinct().ToList(); itemGridView.ItemsSource = dps; success = true; } } catch (Exception) { success = false; } if (!success) { MessageDialog m = new MessageDialog("There was some error in fetching content. Please try after sometime.", "Oops!"); await m.ShowAsync(); } progbar.Visibility = Visibility.Collapsed; }
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; } } }
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; } }