コード例 #1
0
        /// <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();
        }
コード例 #2
0
        /// <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();
        }