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; }
/** * Constructor for Player Object */ public DirectShowPlayer() { graphBuilder = null; _IsPlaying = false; PreviousVolume = null; loadedSong = null; }
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; }
protected void CheckForStationTags(PandoraSong song) { if (!RemoveStationTags) { return; } foreach (string currTag in specialStationTags) { if (song.Artist.EndsWith(currTag)) { song.Artist = song.Artist.Remove(song.Artist.LastIndexOf(currTag)).Trim(); return; } } }
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); } }
public void TemporarilyBanSong(PandoraSong song) { try { Core.MusicBox.TemporarilyBanSong(song); if (song == Core.MusicBox.CurrentSong) { PlayNextTrack(); } UpdateGUI(); } catch (Exception ex) { GracefullyFail(ex); } }
/// <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); } }
// 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); } }
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); } }
/// <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)); }
public void GetSongLength(PandoraUser user, PandoraSong song) { GetSongLength(user, song, null); }
private void PlayNextTrack(bool ignoreSkip) { if (!initialized) { return; } Thread work = new Thread(new ThreadStart(delegate { Thread.Sleep(50); try { if (!IsStillListening()) { return; } setWorkingAnimationStatus(true); // if this is a skip event, check if it is allowed and notify the user if it is not bool isSkip = PlayingRadio && !ignoreSkip; if (isSkip && !Core.MusicBox.CanSkip()) { logger.Info("User is not currently allowed to skip tracks."); ShowMessage("Pandora", "Unfortunately our music licenses force", "us to limit the number of songs you may", "skip. If want to hear something else,", "try switching to another station."); return; } if (isSkip) { logger.Info("Skipping Current Track"); } logger.Debug("Attempting to Start Next Track"); // grab the next song and have MediaPortal start streaming it PandoraSong song = Core.MusicBox.GetNextSong(isSkip); PlayStreamDelegate playStreamSafe = g_Player.PlayAudioStream; GUIGraphicsContext.form.Invoke(playStreamSafe, new object[] { song.AudioURL }); logger.Info("Started: '" + song.Title + "' by " + song.Artist); UpdateGUI(); } catch (Exception ex) { GracefullyFail(ex); } finally { setWorkingAnimationStatus(false); } })); work.IsBackground = true; work.SetApartmentState(ApartmentState.STA); work.Start(); }
public void AddTiredSong(PandoraSession session, PandoraSong song) { AddTiredSong(session, song, null); }
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); }
public PandoraSongFeedback RateSong(PandoraSession session, PandoraStation station, PandoraSong song, PandoraRating rating) { return(RateSong(session, station, song, rating, null)); }
/// <summary> /// Ban this song from playing on any of the users stations for one month. /// </summary> /// <param name="song"></param> public void TemporarilyBanSong(PandoraSong song) { VerifyAndExecute(delegate { pandora.AddTiredSong(Session, song, Proxy); }); }
/// <summary> /// Rate the specified song. A positive or negative rating will influence future songs /// played from the current station. /// </summary> /// <param name="rating"></param> /// <param name="song"></param> public void RateSong(PandoraSong song, PandoraRating rating) { VerifyAndExecute(delegate { pandora.RateSong(Session, CurrentStation, song, rating); }); }
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); } }