示例#1
0
		/// <summary>
		/// Relays a Now Playing report to the underlying
		/// connection. For luxury purposes only.
		/// </summary>
		/// <param name="track">
		/// A <see cref="NowplayingTrack"/>
		/// </param>
		public void ReportNowplaying(NowplayingTrack track)
		{
			Connection.ReportNowplaying(track);
		}
        public void NowPlaying(YouTubeEntry song)
        {
            if (!IsLoged)
            return;
              try
              {
            string Artist = string.Empty;
            string Title = string.Empty;
            int length = 0;
            string _title = song.Title.Text;
            if (_title.Contains("-"))
            {
              Artist = _title.Split('-')[0].Trim();
              Title = _title.Split('-')[1].Trim();
            }
            if (song.Duration != null && song.Duration.Seconds != null)
            {
              length = Convert.ToInt32(song.Duration.Seconds, 10);
            }

            if (!string.IsNullOrEmpty(Artist) && !string.IsNullOrEmpty(Title) && length > 0)
            {
              NowplayingTrack track1 = new NowplayingTrack(Artist, Title, new TimeSpan(0, 0, length));
              manager.ReportNowplaying(track1);
            }
              }
              catch (Exception exception)
              {
            Log.Error(exception);
              }
        }
示例#3
0
		/// <summary>
		/// Send the now playing notification.
		/// </summary>
		/// <param name="track">
		/// A <see cref="NowplayingTrack"/>
		/// </param>
		public void ReportNowplaying(NowplayingTrack track)
		{
			Initialize();
			
			RequestParameters p = new RequestParameters();
			p["s"] = SessionID;
			p["a"] = track.Artist;
			p["t"] = track.Title;
			p["b"] = track.Album;

			if (track.Duration.TotalSeconds == 0)
				p["l"] = "";
			else
				p["l"] = track.Duration.TotalSeconds.ToString();
			
			if (track.Number == 0)
				p["n"] = "";
			else
				p["n"] = track.Number.ToString();
			
			p["m"] = track.MBID;

			Request request = new Request(this.NowplayingURL, p);

			// A BadSessionException occurs when another client has made a handshake
			// with this user's credentials, should redo a handshake and pass this 
			// exception quietly.
			try
			{
				request.execute();
			} catch (BadSessionException) {
				this.doHandshake();
				this.ReportNowplaying(track);
			}
		}
示例#4
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            InvokeStarted(null);
            Trace.WriteLine("Started");

            Track lastPlayingTrack = null;
            Track lastScrobbledTrack = null;
            Track lastTrack = null;
            var lastPlayedTrackStarted = DateTime.Now;
            var cycles = 0;

            while (!worker.CancellationPending)
            {
                if (cycles == 0)
                {
                    cycles = 15; // 15 seconds approx.
                    var track = GetCurrentTrack(feedUrl);
                    var lastPlayedTrackHasChanged = (lastPlayingTrack != null && !lastPlayingTrack.Equals(track));
                    var isFirstTime = (lastTrack == null || !lastTrack.Equals(track));

                    if (lastPlayedTrackHasChanged)
                    {
                        var newScrobbledTrack = (lastScrobbledTrack == null || !lastScrobbledTrack.Equals(lastPlayingTrack));
                        var duration = DateTime.Now - lastPlayedTrackStarted;
                        if (newScrobbledTrack && duration > new TimeSpan(0, 0, 0, 30))
                        {
                            var entry = new Entry(
                                lastPlayingTrack.Artist,
                                lastPlayingTrack.Title,
                                lastPlayedTrackStarted,
                                PlaybackSource.NonPersonalizedBroadcast,
                                duration,
                                ScrobbleMode.Played
                                );
                            scrobbleManager.Queue(entry);
                            lastScrobbledTrack = lastPlayingTrack;
                            InvokeScrobbled(new TrackEventArgs() {Track = lastPlayingTrack});
                            Trace.WriteLine(String.Format("Scrobbled: {0} ({1})", lastPlayingTrack, duration));
                        }
                        lastPlayedTrackStarted = DateTime.Now;
                    }
                    if (track.Status == TrackStatus.Playing)
                    {
                        var duration = DateTime.Now - lastPlayedTrackStarted;
                        NotifyMsnMessenger(track);
                        if (configuration.NotifyLastFm)
                        {
                            var nowplayingTrack = new NowplayingTrack(track.Artist, track.Title, duration);
                            scrobbleManager.ReportNowplaying(nowplayingTrack);
                        }
                        Trace.WriteLine(String.Format("Now playing: {0} ({1})", track, duration));
                        lastPlayingTrack = track;
                        lastPlayedTrack = track;
                    }
                    else
                    {
                        NotifyMsnMessenger(null);
                        lastPlayingTrack = null;
                        if (lastPlayedTrack.Status == TrackStatus.Playing)
                        {
                            lastPlayedTrack.Status = TrackStatus.Played;
                        }
                        Trace.WriteLine(String.Format("{0}: {1}", track.Status, track));
                    }
                    InvokePlaying(new PlayingEventArgs
                    {
                        Track = track,
                        IsFirstTime = isFirstTime
                    });
                    lastTrack = track;
                }
                cycles--;
                Thread.Sleep(1000);
            }
            InvokeStopped(null);
            Trace.WriteLine("Stopped");
        }