/// <summary> /// Returns the next song and updates the CurrentSong property. Will throw a PandoraException if /// skipping and the user is not allowed to skip at this point in time. Call CanSkip() first as needed. /// </summary> /// <returns></returns> public PandoraSong GetNextSong(bool isSkip) { // update the previous songs list while (PreviousSongs.Count > 4) { PreviousSongs.RemoveAt(4); } // if necessary log a skip event. this will throw an exception if a skip is not allowed if (isSkip) { SkipHistory.Skip(CurrentStation); } if (CurrentSong != null) { // update playback history PreviousSongs.Insert(0, CurrentSong); // keep track of how much listening time has occured since our last ad TimeSpan realDuration = DateTime.Now - (DateTime)timeLastSongGrabbed; if (realDuration > CurrentSong.Length) { timeSinceLastAd = timeSinceLastAd.Add(CurrentSong.Length); } else { timeSinceLastAd = timeSinceLastAd.Add(realDuration); } } timeLastSongGrabbed = DateTime.Now; // grab the next song in our queue. songs become invalid after an // unspecified number of hours. do { if (playlist.Count < 2) { LoadMoreSongs(); } CurrentSong = playlist.Dequeue(); } while (!pandora.IsValid(CurrentSong, Proxy)); pandora.GetSongLength(User, CurrentSong, Proxy); return(CurrentSong); }
protected void Clear() { if (PreviousSongs == null) { PreviousSongs = new List <PandoraSong>(); } if (AvailableStations == null) { AvailableStations = new List <PandoraStation>(); } _currentStation = null; CurrentSong = null; PreviousSongs.Clear(); AvailableStations.Clear(); SkipHistory = null; User = null; playlist.Clear(); }