Beispiel #1
0
 public static async Task<trackInfo> getInfo(string artistName, string trackName, string username = "")
 {
     RequestParameters rParams = new RequestParameters("track.getinfo");
     rParams.Add("artist", artistName);
     rParams.Add("track", trackName);
     if (!string.IsNullOrEmpty(username))
         rParams.Add("username", username);
     XDocument returnedXml = await Request.MakeRequest(rParams);
     if (Request.CheckStatus(returnedXml) == 0)
     {
         trackInfo track = new trackInfo(returnedXml.Element("lfm").Element("track"));
         return track;
     }
     else if (Request.CheckStatus(returnedXml) == 6) // Track not found
     {
         // Trying with autocorrect
         rParams.Add("autocorrect", "1");
         returnedXml = await Request.MakeRequest(rParams);
         if (Request.CheckStatus(returnedXml) == 0)
         {
             trackInfo track = new trackInfo(returnedXml.Element("lfm").Element("track"));
             return track;
         }
         else
             throw new LastFmAPIException(returnedXml);
     }
     else
         throw new LastFmAPIException(returnedXml);
 }
Beispiel #2
0
 /// <summary>
 /// Event being fired when track was changed
 /// </summary>
 void ActiveSongChanged(object sender, EventArgs e)
 {
     // Update info about now playing song
     UpdateNowPlayingPivot();
     if (Session.AutoScrobbling == true)
     {
         if (NetworkInterface.GetIsNetworkAvailable())
         {
             // Scrobble song that ended playing 
             // Last.fm recommends scrobbling at the end of the song
             if (LastSong != null)
             {
                 Scrobble(LastSong, LastSongBegan);
             }
             LastSong = MediaPlayer.Queue.ActiveSong;
             LastSongBegan = DateTime.Now;
             UpdateNowPlaying();
         }
         else
         {
             // Offline scrobbling
             trackInfo track = new trackInfo(MediaPlayer.Queue.ActiveSong, DateTime.Now);
             if (Session.Scrobbles.Contains(track))
                 Scrobbling.Scrobble();
             else
                 Session.Scrobbles.Add(new trackInfo(MediaPlayer.Queue.ActiveSong, DateTime.Now));
         }
     }
 }
Beispiel #3
0
        private async void getTrackInfo(string artistName, string trackName)
        {
            // Notify user that request is being processed
            SystemTray.IsVisible = true;
            prog.IsVisible = true;
            prog.IsIndeterminate = true;
            prog.Text = "Loading...";

            // Download track information
            try 
            {
                if (Session.CanUseCurrentSession())
                    currTrack = await track.getInfo(artistName, trackName, Session.CurrentSession.UserName); 
                else
                    currTrack = await track.getInfo(artistName, trackName); 
            }
            catch (TaskCanceledException) { }

            // Show track information to the user
            this.DataContext = currTrack;

            // Show track description
            string htmlDescription = utilities.makeHtmlFromCdata(currTrack.description, currTrack.extralargeImage);
            string descriptionFileName = utilities.SaveStringToFile(htmlDescription, "track.html");
            trackDescription.Navigate(new Uri(descriptionFileName, UriKind.Relative));

            // Add album link
            if (currTrack.album != null)
                AlbumLink.NavigateUri = utilities.getAlbumInfoPageUri(artistName, currTrack.album.name);

            UpdateAppbar();

            // Notify user that request was completed
            prog.IsIndeterminate = false;
            prog.IsVisible = false;
            SystemTray.IsVisible = false;
        }