/// <summary> /// Called when the agent request is getting cancelled /// The call to base.OnCancel() is necessary to release the background streaming resources /// </summary> protected override void OnCancel() { base.OnCancel(); // The shutdown calls NotifyComplete(), so we don't have to call it here. AudioTrackStreamer.ShutdownMediaStreamSource(); }
/// <summary> /// Called when the user requests an action using application/system provided UI /// </summary> /// <param name="player">The BackgroundAudioPlayer</param> /// <param name="track">The track playing at the time of the user action</param> /// <param name="action">The action the user has requested</param> /// <param name="param">The data associated with the requested action. /// In the current version this parameter is only for use with the Seek action, /// to indicate the requested position of an audio track</param> /// <remarks> /// User actions do not automatically make any changes in system state; the agent is responsible /// for carrying out the user actions if they are supported. /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks. /// </remarks> protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { System.Diagnostics.Debug.WriteLine(System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + ": OnUserAction() - {0}", action); switch (action) { case UserAction.Play: // Since we are just restarting the same stream, this should be fine. AudioTrackStreamer.ShutdownMediaStreamSource(); player.Track = track; break; case UserAction.Stop: // Stop the background streaming agent. AudioTrackStreamer.ShutdownMediaStreamSource(); break; case UserAction.Pause: player.Stop(); // Stop the background streaming agent. AudioTrackStreamer.ShutdownMediaStreamSource(); break; case UserAction.FastForward: break; case UserAction.Rewind: break; case UserAction.Seek: break; case UserAction.SkipNext: break; case UserAction.SkipPrevious: break; } NotifyComplete(); }