Example #1
0
        public void AddTiredSong(PandoraSession session, PandoraSong song, WebProxy proxy)
        {
            if (session == null || session.User == null) throw new PandoraException("User must be logged in to make this request.");

            ExecuteRequest(new SleepSongRequest(session, song.Token), proxy);
            song.TemporarilyBanned = true;
        }
Example #2
0
        // estimate the length of each song based on file size
        public void GetSongLength(PandoraUser user, PandoraSong song, WebProxy proxy)
        {
            if (!IsValid(song, proxy)) {
                throw new PandoraException("Attempting to get song length for an expired song.");
            }

            WebRequest request = WebRequest.Create(song.AudioURL);
            if (proxy != null) request.Proxy = proxy;
            request.Method = "HEAD";

            using (WebResponse response = request.GetResponse()) {
                long bytes = response.ContentLength;
                int seconds = (int)((bytes * 8) / (int.Parse(song.AudioInfo.Bitrate) * 1000));
                song.Length = new TimeSpan(0, 0, seconds);
            }
        }
 /**
  * Constructor for Player Object
  */
 public DirectShowPlayer() {
     graphBuilder = null;
     _IsPlaying = false;
     PreviousVolume = null;
     loadedSong = null;
 }
        public void Close() {
            // store current volume so it persists from track to track
            if (loadedSong != null)
                PreviousVolume = Volume;

            Stop();

            lock (lockingToken) {
                mediaEventEx = null;
                mediaSeeking = null;
                mediaControl = null;
                mediaPosition = null;
                basicAudio = null;

                if (this.graphBuilder != null)
                    Marshal.ReleaseComObject(this.graphBuilder);
                this.graphBuilder = null;
            }

            loadedSong = null;
            _IsPlaying = false;
        }
        public bool Open(PandoraSong file) {
            try {
                Close();

                graphBuilder = (IGraphBuilder)new FilterGraph();

                // create interface objects for various actions
                mediaControl = (IMediaControl)graphBuilder;
                mediaEventEx = (IMediaEventEx)graphBuilder;
                mediaSeeking = (IMediaSeeking)graphBuilder;
                mediaPosition = (IMediaPosition)graphBuilder;
                basicAudio = (IBasicAudio)graphBuilder;

                int hr = 0;

                StartEventLoop();

                //hr = graphBuilder.AddFilter(

                // Have the graph builder construct its the appropriate graph automatically
                hr = graphBuilder.RenderFile(file.AudioURL, null);
                DsError.ThrowExceptionForHR(hr);

                // maintain previous volume level so it persists from track to track
                if (PreviousVolume != null)
                    Volume = (double)PreviousVolume;

                loadedSong = file;
                return true;
            }
            catch (Exception) {
                return false;
            }

        }
        private void ShowSongContext(PandoraSong song)
        {
            if (song.IsAdvertisement) return;

            IDialogbox dialog = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);
            dialog.Reset();
            dialog.SetHeading("Song Options - " + song.Title);

            GUIListItem thumbsUpItem = new GUIListItem("I like this song.");
            dialog.Add(thumbsUpItem);

            GUIListItem thumbsDownItem = new GUIListItem("I don't like this song.");
            dialog.Add(thumbsDownItem);

            GUIListItem tempBanItem = new GUIListItem("I am tired of this song.");
            dialog.Add(tempBanItem);
            dialog.DoModal(GUIWindowManager.ActiveWindow);

            GUIListItem whySelectedItem = new GUIListItem("Why was this song selected?");
            //dialog.Add(whySelectedItem);

            GUIListItem moveSongItem = new GUIListItem("Move Song to Another Station...");
            dialog.Add(moveSongItem);

            if (dialog.SelectedId == thumbsUpItem.ItemId) {
                RateSong(song, PandoraRating.Love);
            }

            else if (dialog.SelectedId == thumbsDownItem.ItemId) {
                RateSong(song, PandoraRating.Hate);
            }

            else if (dialog.SelectedId == whySelectedItem.ItemId) {
                // todo: show the reason song was selected
            }

            else if (dialog.SelectedId == moveSongItem.ItemId) {
                PandoraStation newStation = ShowStationChooser();
                if (newStation != null) {
                    // todo: move song to new station
                }
            }

            else if (dialog.SelectedId == tempBanItem.ItemId) {
                TemporarilyBanSong(song);
            }
        }
        public void TemporarilyBanSong(PandoraSong song)
        {
            try {
                Core.MusicBox.TemporarilyBanSong(song);
                if (song == Core.MusicBox.CurrentSong)
                    PlayNextTrack();

                UpdateGUI();
            }
            catch (Exception ex) {
                GracefullyFail(ex);
            }
        }
        public void RateSong(PandoraSong song, PandoraRating rating)
        {
            try {
                Core.MusicBox.RateSong(song, rating);
                if (rating == PandoraRating.Hate && song == Core.MusicBox.CurrentSong)
                    PlayNextTrack();

                UpdateGUI();
            }
            catch (Exception ex) {
                GracefullyFail(ex);
            }
        }
Example #9
0
 public void GetSongLength(PandoraUser user, PandoraSong song)
 {
     GetSongLength(user, song, null);
 }
Example #10
0
 public void AddTiredSong(PandoraSession session, PandoraSong song)
 {
     AddTiredSong(session, song, null);
 }
Example #11
0
        public PandoraSongFeedback RateSong(PandoraSession session, PandoraStation station, PandoraSong song, PandoraRating rating, WebProxy proxy)
        {
            if (session == null || session.User == null) throw new PandoraException("User must be logged in to make this request.");

            PandoraSongFeedback feedbackObj = (PandoraSongFeedback)ExecuteRequest(new AddFeedbackRequest(session, station.Token, song.Token, rating == PandoraRating.Love), proxy);
            song.Rating = rating;

            return feedbackObj;
        }
Example #12
0
 public PandoraSongFeedback RateSong(PandoraSession session, PandoraStation station, PandoraSong song, PandoraRating rating)
 {
     return RateSong(session, station, song, rating, null);
 }
Example #13
0
        /// <summary>
        /// Returns true if the given PandoraSong is still valid. Links will expire after an unspecified
        /// number of hours.
        /// </summary>
        public bool IsValid(PandoraSong song, WebProxy proxy)
        {
            try {
                WebRequest request = WebRequest.Create(song.AudioURL);
                if (proxy != null) request.Proxy = proxy;
                request.Method = "HEAD";

                using (WebResponse response = request.GetResponse()) {
                    long bytes = response.ContentLength;
                }

                return true;
            }
            catch (WebException) {
                return false;
            }
        }
Example #14
0
 /// <summary>
 /// Returns true if the given PandoraSong is still valid. Links will expire after an unspecified
 /// number of hours.
 /// </summary>
 public bool IsValid(PandoraSong song)
 {
     return IsValid(song, null);
 }