コード例 #1
0
        /// <summary>
        /// Logs into Pandora with the given credentials.
        /// </summary>
        /// <returns>true if the user was successfully logged in.</returns>
        public bool Login(string username, string password)
        {
            Clear();

            Session = pandora.PartnerLogin(Proxy);
            User    = pandora.UserLogin(Session, username, password, Proxy);
            if (User != null && User.CanListen)
            {
                SkipHistory = new SkipHistory(User);

                AvailableStations = pandora.GetStations(Session, Proxy);
                pandora.GetGenreStations(Session, Proxy);

                // try to grab the first station in the list that is not the quickmix station
                foreach (PandoraStation currStation in AvailableStations)
                {
                    if (!currStation.IsQuickMix)
                    {
                        CurrentStation = currStation;
                        break;
                    }
                }

                return(true);
            }

            Clear();
            return(false);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
 /// <summary>
 /// Returns true if the user is allowed to skip the current track on the current station
 /// </summary>
 /// <returns></returns>
 public bool CanSkip()
 {
     return(SkipHistory.CanSkip(CurrentStation));
 }