コード例 #1
0
        /// <summary>
        /// Submit track to Last.FM Library
        /// </summary>
        /// <param name="Artist"></param>
        /// <param name="Title"></param>
        public void Submit(string Artist, string Title, int Seconds)
        {
            // Check how much of track was played if less than 50% do not submit
              TimeSpan playTime = DateTime.Now - trackStartTime;
              logger.Debug("Last.FM Submit: {0} {1}", playTime.Seconds.ToString(), (Seconds / 2).ToString());
              if (playTime.Seconds < (Seconds / 2))
            return;

              if (!IsLoged)
            return;
              try
              {
            if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title))
            {
              RequestParameters submitParameters = new RequestParameters();
              submitParameters["artist"] = Artist;
              submitParameters["track"] = Title;
              submitParameters["timestamp"] = calculateSeconds(trackStartTime).ToString();
              Request nowplaying = new Request("track.scrobble", Session, submitParameters);
              XmlDocument doc = nowplaying.execute();
              // Check the Status
              XmlNode n = doc.GetElementsByTagName("lfm")[0];
              string status = n.Attributes[0].InnerText;
              logger.Debug("Call to track.scrobble : " + status);
            }
              }
              catch (Exception exception)
              {
            logger.DebugException("Error in Submit",exception);
              }
        }
コード例 #2
0
 /// <summary>
 /// Update now playing track on Last.FM
 /// </summary>
 /// <param name="Artist"></param>
 /// <param name="Title"></param>
 /// <param name="seconds"></param>
 public void NowPlaying(string Artist, string Title, int seconds)
 {
     if (!IsLoged)
     return;
       try
       {
     if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title) && seconds > 0)
     {
       RequestParameters nowPlayingParameters = new RequestParameters();
       nowPlayingParameters["track"] = Title;
       nowPlayingParameters["artist"] = Artist;
       nowPlayingParameters["duration"] = seconds.ToString();
       Request nowplaying = new Request("track.updateNowPlaying", Session, nowPlayingParameters);
       XmlDocument doc = nowplaying.execute();
       // Check the status
       XmlNode n = doc.GetElementsByTagName("lfm")[0];
       string status = n.Attributes[0].InnerText;
       logger.Debug("Call to track.updateNowPlaying : " + status);
       trackStartTime = DateTime.Now;
     }
       }
       catch (Exception exception)
       {
     logger.DebugException("Error with Nowplayin", exception);
       }
 }