/// <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) { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Pause: if (PlayState.Playing == player.PlayerState) { player.Pause(); } break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.SkipNext: PlayNextTrack(player); break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (PlayState.Playing != player.PlayerState) { player.Track = _playList[currentTrackNumber]; } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: if (PlayState.Playing == player.PlayerState) { player.Pause(); } break; case UserAction.FastForward: // Fast Forward only works with non-MSS clients. // If the Source is null, we are streaming an MSS. if (track.Source != null) { player.FastForward(); } break; case UserAction.Rewind: // Rewind only works with non-MSS clients. // If the Source is null, we are streaming an MSS. if (track.Source != null) { player.Rewind(); } break; case UserAction.Seek: // Seek only works with non-MSS clients. // If the Source is null, we are streaming an MSS. if (track.Source != null) { player.Position = (TimeSpan)param; } break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: player.Track = GetPreviousTrack(); break; } NotifyComplete(); }
/// <summary> /// Called when the playstate changes, except for the Error state (see OnError) /// </summary> /// <param name="player">The BackgroundAudioPlayer</param> /// <param name="track">The track playing at the time the playstate changed</param> /// <param name="playState">The new playstate of the player</param> /// <remarks> /// Play State changes cannot be cancelled. They are raised even if the application /// caused the state change itself, assuming the application has opted-in to the callback. /// /// Notable playstate events: /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track. /// (b) TrackReady: an audio track has been set and it is now ready for playack. /// /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks. /// </remarks> protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState) { switch (playState) { case PlayState.TrackEnded: player.Track = GetPreviousTrack(); break; case PlayState.TrackReady: player.Play(); break; case PlayState.Shutdown: // TODO: Handle the shutdown state here (e.g. save state) break; case PlayState.Unknown: break; case PlayState.Stopped: break; case PlayState.Paused: player.Pause(); break; case PlayState.Playing: break; case PlayState.BufferingStarted: break; case PlayState.BufferingStopped: break; case PlayState.Rewinding: break; case PlayState.FastForwarding: break; } NotifyComplete(); }
/// <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) { try { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Pause: player.Pause(); break; case UserAction.Stop: player.Stop(); break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.SkipNext: PlayNextTrack(player); break; } } catch { } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; default: break; } NotifyComplete(); }
protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (PlayState.Playing != player.PlayerState) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: if (PlayState.Playing == player.PlayerState) { player.Pause(); } break; case UserAction.Rewind: player.Position = player.Position.Subtract(new TimeSpan(0,0,10)); break; case UserAction.FastForward: player.Position = player.Position.Add(new TimeSpan(0,0,10)); break; } NotifyComplete(); }
protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { ShellTile mainTile = ShellTile.ActiveTiles.FirstOrDefault(); switch (action) { case UserAction.Play: if (PlayState.Paused == player.PlayerState) { player.Play(); mainTile.Update(new StandardTileData { BackContent = "Play" }); } break; case UserAction.Pause: player.Pause(); mainTile.Update(new StandardTileData { BackContent = "Pause" }); break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Pause: player.Pause(); break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.SkipNext: PlayNextTrack(player); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; } NotifyComplete(); }
/// <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) { try { switch (action) { case UserAction.Play: player.Play(); break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: try { player.Position = (TimeSpan)param; } catch (InvalidOperationException) { // thrown occasionally. what to do? } break; case UserAction.SkipNext: var maybeNext = GetNextTrack(); if (maybeNext != null) { player.Track = maybeNext; // no need to play as playback is started when the track is "ready" //player.Play(); } break; case UserAction.SkipPrevious: var maybePrevious = GetPreviousTrack(); if (maybePrevious != null) { player.Track = maybePrevious; //player.Play(); } break; } } catch (Exception) { // Might throw SystemException on some rare occasions? // TODO: reproduce, handle exception var tmp = 0; } NotifyComplete(); }
/// <summary> /// Called when the user requests an action using system-provided UI and the application has requesed /// notifications of the action /// </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 /// </remarks> protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { if (action == UserAction.Play) player.Play(); else if (action == UserAction.Pause) player.Pause(); NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState == PlayState.Paused) { PopulatePlaylist(false); } else { PopulatePlaylist(true); } if (currentPlaylist != null && currentPlaylist.Count > 0) { player.Track = currentPlaylist[currentTrackNumber]; } break; case UserAction.Stop: currentPlaylist = null; currentTrackNumber = 0; player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: if (currentPlaylist != null && currentPlaylist.Count > 0) { player.Track = GetNextTrack(); } break; case UserAction.SkipPrevious: if (currentPlaylist != null && currentPlaylist.Count > 0) { player.Track = GetPreviousTrack(); } break; } NotifyComplete(); }
/// <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 async override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: { AudioTrack newTrack = await GetNextStation(player.Track.Artist); if (track != null) { player.Track = newTrack; } break; } case UserAction.SkipPrevious: { AudioTrack newTrack = await GetPreviousStation(player.Track.Artist); if (track != null) { player.Track = newTrack; } break; } } NotifyComplete(); }
public void PlayPause(object arg) { if (_memo != null) { if (App.SettingsHelper.UseSystemPlayer) { MediaPlayerLauncher playerLauncher = new MediaPlayerLauncher(); playerLauncher.Controls = MediaPlaybackControls.FastForward | MediaPlaybackControls.Rewind | MediaPlaybackControls.Pause | MediaPlaybackControls.Stop; playerLauncher.Location = MediaLocationType.Data; playerLauncher.Media = new Uri(_memo.AudioFile, UriKind.RelativeOrAbsolute); playerLauncher.Orientation = MediaPlayerOrientation.Portrait; if (!_memo.IsPlayed) { _memo.IsPlayed = true; //Uow.Save(); } playerLauncher.Show(); } else { if (_instance.Track == null) { SetAudioTrack(_memo.AudioFile, _memo.Title); } if (!_instance.Track.Source.OriginalString.Contains(_memo.AudioFile)) { SetAudioTrack(_memo.AudioFile, _memo.Title); } if (_instance.PlayerState != PlayState.Playing) { _instance.Play(); if (!_memo.IsPlayed) { _memo.IsPlayed = true; Uow.MemoRepository.Update(_memo); //Uow.Save(); } } else { if (_instance.CanPause) { _instance.Pause(); } } } } }
/// <summary> /// Called when the user requests an action using system-provided UI and the application has requesed /// notifications of the action /// </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 /// </remarks> protected override void OnUserAction( BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Stop: try { if (player.PlayerState != PlayState.Paused || !PlayerService.NowPlayingExists()) { this.Lifetime.Add((from _ in this.LoadNowPlayingAsync() from __ in this.StopPlayingAsync(player) select __).Finally(this.Completed).Subscribe(_ => { }, ex => this.ReportFatalStopError(ex, null))); return; } } catch (InvalidOperationException) { // Uh oh background resources not available. } break; case UserAction.Pause: try { player.Pause(); } catch (InvalidOperationException) { // Probably no track.. just continue on our merry way } break; case UserAction.Play: this.Lifetime.Add((from _ in this.LoadNowPlayingAsync() from __ in this.PlayTrackAsync(player) select __).ObserveOn(Scheduler.CurrentThread).Finally(this.Completed).Subscribe(_ => { }, ex => this.ReportFatalStopError(ex, null))); return; case UserAction.SkipNext: this.Lifetime.Add((from _ in this.LoadNowPlayingAsync() from __ in this.SkipToNextTrackAsync(player) select __).ObserveOn(Scheduler.CurrentThread).Finally(this.Completed).Subscribe(_ => { }, ex => this.ReportFatalStopError(ex, null))); return; } this.Completed(); }
/// <summary> /// 在用户使用应用程序/系统提供的用户界面请求操作时调用 /// </summary> /// <param name="player">BackgroundAudioPlayer</param> /// <param name="track">用户操作期间播放的曲目</param> /// <param name="action">用户请求的操作</param> /// <param name="param">与请求的操作相关联的数据。 /// 在当前版本中,此参数仅适合与 Seek 操作一起使用, /// 以指明请求的乐曲的位置</param> /// <remarks> /// 用户操作不自动对系统状态进行任何更改;如果用户操作受支持, /// 以便执行用户操作(如果这些操作受支持)。 /// /// 只在代理请求完成之后调用 NotifyComplete() 一次,包括异步回调。 /// </remarks> protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { if (player.PlayerState != PlayState.Paused) { player.Track = track; } else { player.Play(); } // player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: AudioTrack previousTrack = GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Pause: player.Pause(); break; } NotifyComplete(); }
protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.FastForward: player.FastForward(); break; case UserAction.Pause: player.Pause(); break; case UserAction.Play: if (player.PlayerState == PlayState.Paused) { player.Play(); } else { Play(player); } break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: PlayNext(player); break; case UserAction.SkipPrevious: PlayPrev(player); break; case UserAction.Stop: player.Stop(); break; default: break; } NotifyComplete(); }
/// <summary> /// 在用户使用应用程序/系统提供的用户界面请求操作时调用 /// </summary> /// <param name="player">BackgroundAudioPlayer</param> /// <param name="track">用户操作期间播放的曲目</param> /// <param name="action">用户请求的操作</param> /// <param name="param">与请求的操作相关联的数据。 /// 在当前版本中,此参数仅适合与 Seek 操作一起使用, /// 以指明请求的乐曲的位置</param> /// <remarks> /// 用户操作不自动对系统状态进行任何更改;如果用户操作受支持, /// 以便执行用户操作(如果这些操作受支持)。 /// /// 只在代理请求完成之后调用 NotifyComplete() 一次,包括异步回调。 /// </remarks> protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } NotifyComplete(); break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: GetNextAudioTrack getnextaudiotrack = new NetGetNextAudioTrack(null); getnextaudiotrack.HaveNextTrack += (s, e) => { BackgroundAudioPlayer.Instance.Track = e.Track; //应该不用加Play() NotifyComplete(); }; getnextaudiotrack.ChangeNextTrack(); break; case UserAction.SkipPrevious: break; } }
public override Uri MapUri(Uri uri) { if (PodcastHelper.HasPodcastUri(uri)) { BackgroundAudioPlayer bap = BackgroundAudioPlayer.Instance; var action = PodcastHelper.RetrievePodcastAction(uri); switch (action.Command) { case PodcastCommand.Launch: // Do nothing. break; case PodcastCommand.Pause: if (bap.CanPause) { bap.Pause(); } break; case PodcastCommand.Play: if (bap.PlayerState != PlayState.Playing) { PodcastPlaybackManager.getInstance().startDefaultBehaviorPlayback(); } break; case PodcastCommand.SkipNext: if (bap.PlayerState == PlayState.Playing) { bap.SkipNext(); } break; case PodcastCommand.SkipPrevious: if (bap.PlayerState == PlayState.Playing) { bap.SkipPrevious(); } break; } return(new Uri("/Views/MainView.xaml", UriKind.Relative)); } // Otherwise perform normal launch. return(uri); }
/// <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("AGENT RECEIVED USER ACTION: " + action.ToString()); switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: AudioTrack previousTrack = GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: Play(player); break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: try { player.Position = (TimeSpan)param; } catch (InvalidOperationException) { // thrown occasionally. what to do? player.Position = TimeSpan.FromSeconds(0); } break; case UserAction.SkipNext: PlayNext(player); break; case UserAction.SkipPrevious: PlayPrevious(player); break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.SkipNext: SkipNext(player, 200); break; case UserAction.SkipPrevious: SkipPrevious(player, 200); break; case UserAction.FastForward: SkipNext(player, 1000); break; case UserAction.Rewind: SkipPrevious(player, 1000); break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: try { if (player.PlayerState != PlayState.Playing) { Debug.WriteLine("User.Action: Play"); player.Play(); } } catch (InvalidOperationException e) { Debug.WriteLine("Exception: " + e.Message); } catch (SystemException syse) { Debug.WriteLine("Exception: " + syse.Message); } break; case UserAction.Stop: try { if (player.PlayerState != PlayState.Stopped) { updatePlayposForCurrentEpisode(player); player.Stop(); Debug.WriteLine("User.Action: Stop"); } } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message); } break; case UserAction.Pause: Debug.WriteLine("User.Action: Pause"); try { if (player.PlayerState == PlayState.Playing) { updatePlayposForCurrentEpisode(player); player.Pause(); } } catch (InvalidOperationException e) { Debug.WriteLine("Exception: " + e.Message); } break; case UserAction.Seek: try { if (player.PlayerState == PlayState.Playing) { player.Position = (TimeSpan)param; } } catch (InvalidOperationException e) { Debug.WriteLine("Exception: " + e.Message); } break; case UserAction.SkipNext: Debug.WriteLine("Skip next."); updatePlayposForCurrentEpisode(player); AudioTrack nextTrack = getNextPlaylistTrack(); if (nextTrack == null) { player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) : TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds); } else { player.Track = nextTrack; player.Play(); } break; case UserAction.FastForward: try { Debug.WriteLine("Player fast forward. New position: " + player.Position); player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) : TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds); } catch (Exception) { Debug.WriteLine("Error seeking. Probably seeked passed the end."); } break; case UserAction.SkipPrevious: case UserAction.Rewind: try { player.Position = (player.Position.TotalSeconds - 30 >= 0) ? TimeSpan.FromSeconds(player.Position.TotalSeconds - 30) : TimeSpan.FromSeconds(0); Debug.WriteLine("Player fast forward. New position: " + player.Position); } catch(Exception) { Debug.WriteLine("Error seeking. Probably seeked passed the start."); } break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Stop: PlayTrack(player); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: AudioTrack previousTrack = GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } break; } NotifyComplete(); }
/// <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 async override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: { AudioTrack newTrack = await GetNextStation(player.Track.Artist); if (track != null) player.Track = newTrack; break; } case UserAction.SkipPrevious: { AudioTrack newTrack = await GetPreviousStation(player.Track.Artist); if (track != null) player.Track = newTrack; break; } } NotifyComplete(); }
/// <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 ) { switch (action) { case UserAction.Play: PlayTrack( player ); break; case UserAction.Pause: player.Pause(); break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: loadfile(); PlayTrack(player); break; case UserAction.Pause: player.Pause(); break; case UserAction.Stop: player.Stop(); break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.SkipNext: PlayNextTrack(player); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player != null && player.PlayerState != PlayState.Playing) { player.Volume = 1; player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: SetNextTrack(player); break; case UserAction.SkipPrevious: SetPreviousTrack(player); break; } NotifyComplete(); }
/// <summary> /// Called when the user requests an action using system-provided UI and the application has requesed /// notifications of the action /// </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 /// </remarks> protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.FastForward: player.FastForward(); break; case UserAction.Pause: player.Pause(); break; case UserAction.Play: if (player.PlayerState == PlayState.Paused) { player.Play(); } else { Play(player); } break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: PlayNext(player); break; case UserAction.SkipPrevious: PlayPrev(player); break; case UserAction.Stop: player.Stop(); break; default: break; } NotifyComplete(); }
/// <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 async void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { await ConfigureThePlayer(); switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { _logger.Info("OnUserAction.Play"); player.Play(); } break; case UserAction.Stop: _logger.Info("OnUserAction.Stop"); player.Stop(); break; case UserAction.Pause: _logger.Info("OnUserAction.Pause"); player.Pause(); break; case UserAction.FastForward: _logger.Info("OnUserAction.FastForward"); player.FastForward(); break; case UserAction.Rewind: _logger.Info("OnUserAction.Rewind"); player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: _logger.Info("OnUserAction.SkipNext"); var nextTrack = await GetNextTrack(); if (nextTrack != null) { player.Track = nextTrack; } await InformOfPlayingTrack(); break; case UserAction.SkipPrevious: _logger.Info("OnUserAction.SkipPrevious"); var previousTrack = await GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } await InformOfPlayingTrack(); break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState == PlayState.Paused) PopulatePlaylist(false); else PopulatePlaylist(true); if (currentPlaylist != null && currentPlaylist.Count > 0) { player.Track = currentPlaylist[currentTrackNumber]; } break; case UserAction.Stop: currentPlaylist = null; currentTrackNumber = 0; player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: if (currentPlaylist != null && currentPlaylist.Count > 0) player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: if (currentPlaylist != null && currentPlaylist.Count > 0) player.Track = GetPreviousTrack(); break; } NotifyComplete(); }
/// <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) { Debug.WriteLine("OnUserAction() action " + action); switch (action) { case UserAction.Play: var task = Task.Run((Func<Task>)RunDownload); if (player.PlayerState != PlayState.Playing) player.Play(); task.ContinueWith(t => NotifyComplete()); return; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: var previousTrack = GetPreviousTrack(); if (previousTrack != null) player.Track = previousTrack; break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: var audioInfo = (from audio in db.AudioPlaylist select audio).FirstOrDefault(); string audioUrl = audioInfo.AudioUrl; string audioTitle = audioInfo.AudioTitle; string audioArtist = audioInfo.AudioArtist; string audioId = audioInfo.Aid; player.Track = new AudioTrack(new Uri(audioUrl), audioTitle, audioArtist, null, null, audioId, EnabledPlayerControls.All); if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: AudioTrack previousTrack = GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } break; } NotifyComplete(); }
/// <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) { Debug.WriteLine("AudioPlayer.OnUserAction() track.Source {0} track.Tag {1} action {2}", null == track ? "<no track>" : null == track.Source ? "<none>" : track.Source.ToString(), null == track ? "<no track>" : track.Tag ?? "<none>", action); try { switch (action) { case UserAction.Play: UpdateTrack(player); if (PlayState.Playing != player.PlayerState && null != player.Track) player.Play(); break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: if (PlayState.Playing == player.PlayerState) player.Pause(); break; case UserAction.FastForward: if (null != track && null != track.Source) player.FastForward(); break; case UserAction.Rewind: if (null != track && null != track.Source) player.Rewind(); break; case UserAction.Seek: if (null != track) player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); if (PlayState.Playing != player.PlayerState && null != player.Track) player.Play(); break; case UserAction.SkipPrevious: var previousTrack = GetPreviousTrack(); if (previousTrack != null) player.Track = previousTrack; if (PlayState.Playing != player.PlayerState && null != player.Track) player.Play(); break; } } catch (Exception ex) { Debug.WriteLine("AudioPlayer.OnUserAction() failed: " + ex.ExtendedMessage()); // Is there anything we can do about this? try { player.Close(); } catch (Exception ex2) { Debug.WriteLine("AudioPlayer.OnUserAction() close failed: " + ex2.ExtendedMessage()); } } finally { NotifyComplete(); } }
/// <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) { switch (action) { case UserAction.Play: try { if (player.PlayerState != PlayState.Playing) { Debug.WriteLine("User.Action: Play"); player.Play(); } } catch (InvalidOperationException e) { Debug.WriteLine("Exception: " + e.Message); } catch (SystemException syse) { Debug.WriteLine("Exception: " + syse.Message); } break; case UserAction.Stop: try { if (player.PlayerState != PlayState.Stopped) { updatePlayposForCurrentEpisode(player); player.Stop(); Debug.WriteLine("User.Action: Stop"); } } catch (Exception e) { Debug.WriteLine("Exception: " + e.Message); } break; case UserAction.Pause: Debug.WriteLine("User.Action: Pause"); try { if (player.PlayerState == PlayState.Playing) { updatePlayposForCurrentEpisode(player); player.Pause(); } } catch (InvalidOperationException e) { Debug.WriteLine("Exception: " + e.Message); } break; case UserAction.Seek: try { if (player.PlayerState == PlayState.Playing) { player.Position = (TimeSpan)param; } } catch (InvalidOperationException e) { Debug.WriteLine("Exception: " + e.Message); } break; case UserAction.SkipNext: Debug.WriteLine("Skip next."); updatePlayposForCurrentEpisode(player); AudioTrack nextTrack = getNextPlaylistTrack(); if (nextTrack == null) { player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) : TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds); } else { player.Track = nextTrack; player.Play(); } break; case UserAction.FastForward: try { Debug.WriteLine("Player fast forward. New position: " + player.Position); player.Position = (player.Position.TotalSeconds + 30 < player.Track.Duration.TotalSeconds) ? TimeSpan.FromSeconds(player.Position.TotalSeconds + 30) : TimeSpan.FromSeconds(player.Track.Duration.TotalSeconds); } catch (Exception) { Debug.WriteLine("Error seeking. Probably seeked passed the end."); } break; case UserAction.SkipPrevious: case UserAction.Rewind: try { player.Position = (player.Position.TotalSeconds - 30 >= 0) ? TimeSpan.FromSeconds(player.Position.TotalSeconds - 30) : TimeSpan.FromSeconds(0); Debug.WriteLine("Player fast forward. New position: " + player.Position); } catch (Exception) { Debug.WriteLine("Error seeking. Probably seeked passed the start."); } break; } NotifyComplete(); }
/// <summary> /// Вызывается при запросе пользователем действия с помощью пользовательского интерфейса приложения или системы /// </summary> /// <param name="player">BackgroundAudioPlayer</param> /// <param name="track">Дорожка, воспроизводимая во время действия пользователя</param> /// <param name="action">Действие, запрошенное пользователем</param> /// <param name="param">Данные, связанные с запрошенным действием. /// В текущей версии этот параметр используется только с действием поиска /// для обозначения запрошенного положения в звуковой дорожке</param> /// <remarks> /// Действия пользователя не изменяют автоматически состояние системы; за выполнение действий /// пользователя, если они поддерживаются, отвечает агент. /// /// Вызовите NotifyComplete() только один раз после завершения запроса агента, включая асинхронные обратные вызовы. /// </remarks> protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { List <string> atrack = DeserializeFromIsolatedStorage <List <string> >("podcast.link"); //AudioTrack pcast = new Uri track_url = new Uri(atrack[0], UriKind.Absolute); if (player.Track == null) { AudioTrack podcast = new AudioTrack(track_url, atrack[1], atrack[2], atrack[3], null); player.Track = podcast; } else if (player.Track.Source != track_url) { AudioTrack podcast = new AudioTrack(track_url, atrack[1], atrack[2], atrack[3], null); player.Track = podcast; } player.Play(); break; } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: AudioTrack previousTrack = GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } break; } NotifyComplete(); }
protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { bool flag = true; try { string str1 = "AudioPlaybackAgent.OnUserAction " + action + " track name=" + track.Title ?? ""; string str2 = !(track.Source != null) ? str1 + ", Source=null" : str1 + ", Source=" + track.Source.ToString(); bool startedNewCycle; switch (action) { case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.Play: if (player.PlayerState != PlayState.Playing) { flag = false; AudioTrackHelper.PlayCurrentTrack(player, (Action <bool>)(res => this.NotifyComplete()), false); break; } break; case UserAction.SkipNext: AudioTrack nextTrack = this.GetNextTrack(player, out startedNewCycle, null); player.Track = nextTrack; flag = false; AudioTrackHelper.PlayCurrentTrack(player, (Action <bool>)(res => this.NotifyComplete()), false); break; case UserAction.SkipPrevious: AudioTrack previousTrack = this.GetPreviousTrack(player, out startedNewCycle, null); player.Track = previousTrack; flag = false; AudioTrackHelper.PlayCurrentTrack(player, (Action <bool>)(res => this.NotifyComplete()), false); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; } if (!flag) { return; } this.NotifyComplete(); } catch { if (!flag) { return; } this.NotifyComplete(); } }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; //case UserAction.FastForward: // player.FastForward(); // break; //case UserAction.Rewind: // player.Rewind(); // break; //case UserAction.Seek: // player.Position = (TimeSpan)param; // break; //case UserAction.SkipNext: //// player.Track = GetNextTrack(); // break; //case UserAction.SkipPrevious: // AudioTrack previousTrack = GetPreviousTrack(); // if (previousTrack != null) // { // player.Track = previousTrack; // } // break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: if (player.CanPause) { player.Pause(); } break; case UserAction.FastForward: if (player.CanSeek) { player.FastForward(); } break; case UserAction.Rewind: if (player.CanSeek) { player.Rewind(); } break; case UserAction.Seek: if (player.CanSeek) { player.Position = (TimeSpan)param; } break; case UserAction.SkipNext: Func <List <GuidToTrackMapping>, AudioTrack, GuidToTrackMapping> defineNextTrackPredicate = (mappings, currentTrack) => { var index = mappings.IndexOf(mappings.Single(o => o.Guid == new Guid(currentTrack.Tag))); index++; if (index >= mappings.Count) { // no random, no repeat ! return(null); } return(new GuidToTrackMapping { Guid = mappings[index].Guid, Track = mappings[index].Track }); }; player.Track = GetNextTrack(track, defineNextTrackPredicate); break; case UserAction.SkipPrevious: Func <List <GuidToTrackMapping>, AudioTrack, GuidToTrackMapping> definePreviousTrackPredicate = (mappings, currentTrack) => { var index = mappings.IndexOf(mappings.Single(o => o.Guid == new Guid(currentTrack.Tag))); index--; if (index < 0) { // no random, no repeat ! return(null); } return(new GuidToTrackMapping { Guid = mappings[index].Guid, Track = mappings[index].Track }); }; AudioTrack previousTrack = GetPreviousTrack(track, definePreviousTrackPredicate); if (previousTrack != null) { player.Track = previousTrack; } break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.Position = TimeSpan.FromSeconds(player.Position.TotalSeconds + 10); Debug.WriteLine("Player fast forward. New position: " + player.Position); break; case UserAction.Rewind: player.Position = TimeSpan.FromSeconds(player.Position.TotalSeconds - 10); Debug.WriteLine("Player rewind. New position: " + player.Position); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Pause: player.Pause(); break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.SkipNext: PlayNextTrack(player); break; case UserAction.Rewind: CancelOutTrack(player); break; } NotifyComplete(); }
protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: if (maxAlbumNumber == -1) { try { playList.Clear(); GetMaxAlbumNumber(); GetList(); } catch { playList.Clear(); //todo.. playList.Add(new AudioTrack(new Uri("http://www.baidu.com"), "error", null, null, null)); } player.Track = playList[currentTrackNumber]; } if (player.Track != null) { player.Play(); } break; case UserAction.Pause: player.Pause(); break; case UserAction.SkipNext: PlayNextTrack(player); break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.FastForward: if (currentAlbumNumber < maxAlbumNumber) { try { ++currentAlbumNumber; GetList(); } catch { --currentAlbumNumber; //todo... playList.Add(new AudioTrack(new Uri("http://www.baidu.com"), "error", null, null, null)); } player.Track = playList[currentTrackNumber]; } break; case UserAction.Rewind: try { --currentAlbumNumber; GetList(); } catch { ++currentAlbumNumber; //todo.. playList.Add(new AudioTrack(new Uri("http://www.baidu.com"), "error", null, null, null)); } player.Track = playList[currentTrackNumber]; break; case UserAction.Stop: break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: //if (player.PlayerState != PlayState.Playing) //{ // to get audio track //player.Track = this.audioTrack; //player.Play(); //} if (player.Track == null) { currentTrack = 0; player.Track = playlist[currentTrack]; } else { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: //player.Track = GetNextTrack(); if (currentTrack < playlist.Count - 1) { currentTrack += 1; player.Track = playlist[currentTrack]; } else { player.Track = null; } break; case UserAction.SkipPrevious: //AudioTrack previousTrack = GetPreviousTrack(); //if (previousTrack != null) //{ //player.Track = previousTrack; //} break; } NotifyComplete(); }
protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param) { switch (action) { case UserAction.Play: PlayTrack(player); break; case UserAction.Pause: try { if (player.CanPause) { player.Pause(); } } catch (UnauthorizedAccessException ex) { // what the f**k?? } break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; case UserAction.SkipNext: PlayNextTrack(player); break; case UserAction.Stop: player.Stop(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (track != null && track.Tag != null) { var data = track.Tag.ToString().Split('$'); var url = data[data.Length - 1]; var type = data[2]; if (type.ToLower() != "shoutcast") { track.Source = new Uri(url); } } //player.Track = new AudioTrack(null, "", "", "", null, track.Tag, EnabledPlayerControls.Pause); if (player.SafeGetPlayerState() != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: if (player.SafeGetPlayerState() == PlayState.Playing) player.Stop(); break; case UserAction.Pause: if (player.SafeGetPlayerState() == PlayState.Playing) player.Pause(); break; case UserAction.FastForward: //player.FastForward(); break; case UserAction.Rewind: //player.Rewind(); break; case UserAction.Seek: //player.Position = (TimeSpan)param; break; case UserAction.SkipNext: //player.Track = GetNextTrack(); break; case UserAction.SkipPrevious: //AudioTrack previousTrack = GetPreviousTrack(); //if (previousTrack != null) //{ // player.Track = previousTrack; //} break; } NotifyComplete(); }
/// <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) { switch (action) { case UserAction.Play: if (player.PlayerState != PlayState.Playing) { player.Play(); } break; case UserAction.Stop: player.Stop(); break; case UserAction.Pause: player.Pause(); break; case UserAction.FastForward: player.FastForward(); break; case UserAction.Rewind: player.Rewind(); break; case UserAction.Seek: player.Position = (TimeSpan)param; break; case UserAction.SkipNext: try { player.Track = GetNextTrack(); } catch (LastTrackException ex) { player.Track = ex.Track; player.Stop(); } break; case UserAction.SkipPrevious: if (player.Position > TimeSpan.FromSeconds(7)) { player.Position = new TimeSpan(0); } else { AudioTrack previousTrack = GetPreviousTrack(); if (previousTrack != null) { player.Track = previousTrack; } } break; } NotifyComplete(); }