Exemplo n.º 1
0
 private void ScrobbleTrack()
 {
     if (!paused)
     {
         try
         {
             songPlayed += DateTime.Now - songsStart;
         }
         catch (Exception ex)
         {
             Diagnostics.Logger.SaveBG("Scrobble !paused" + Environment.NewLine + ex.Data + Environment.NewLine + ex.Message);
             Diagnostics.Logger.SaveToFileBG();
         }
     }
     if (songPlayed.TotalSeconds >= BackgroundMediaPlayer.Current.NaturalDuration.TotalSeconds * 0.5 || songPlayed.TotalSeconds >= 4 * 60)
     {
         int seconds = 0;
         try
         {
             DateTime start = DateTime.UtcNow - songPlayed;
             seconds = (int)start.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
         }
         catch (Exception ex)
         {
             Diagnostics.Logger.SaveBG("Scrobble paused" + Environment.NewLine + ex.Data + Environment.NewLine + ex.Message);
             Diagnostics.Logger.SaveToFileBG();
             return;
         }
         string        artist    = playlist.GetCurrentSong().Artist;
         string        track     = playlist.GetCurrentSong().Title;
         string        timestamp = seconds.ToString();
         TrackScrobble scrobble  = new TrackScrobble()
         {
             Artist    = artist,
             Track     = track,
             Timestamp = timestamp
         };
         //System.Diagnostics.Debug.WriteLine("scrobble " + artist + " " + track + " " + songPlayed);
         //SendScrobble(scrobble);
         LastFmManager.Current.CacheTrackScrobble(scrobble);
     }
 }
Exemplo n.º 2
0
 private async Task SendScrobble(TrackScrobble s)
 {
     await Task.Run(() => LastFmManager.Current.CacheTrackScrobble(s));
 }
Exemplo n.º 3
0
 public void CacheTrackScrobble(TrackScrobble scrobble)
 {
     DatabaseManager.Save("track.scrobble", scrobble.Artist, scrobble.Track, scrobble.Timestamp);
 }