Example #1
0
        public SkillResponse Loop(AudioSessionAttributes attributes, bool loopEnable)
        {
            attributes.Loop = loopEnable;

            return(Speech.GetTellResponse($"Loop turned {(loopEnable ? "on" : "off")}", false));
        }
Example #2
0
 internal SkillResponse Unhandled(AudioSessionAttributes attributes) => Speech.GetAskResponse("Sorry, I could not understand. Please say, play the audio, to begin the audio.");
Example #3
0
        internal SkillResponse Help(AudioSessionAttributes attributes) => Speech.GetAskResponse("Welcome"); // TODO: extract message constants, same as launch string

        internal SkillResponse StopCancel(AudioSessionAttributes attributes) => Speech.GetTellResponse("Thanks for listening.", true);
Example #4
0
 internal SkillResponse Help(AudioSessionAttributes attributes) => Speech.GetAskResponse("Welcome"); // TODO: extract message constants, same as launch string
Example #5
0
 internal SkillResponse UnhandledWhilePlaying(AudioSessionAttributes attributes)
 {
     return(Speech.GetAskResponse(
                "Sorry, I could not understand. You can say, Next or Previous to navigate through the episodes."));
 }
Example #6
0
        public SkillResponse HandleStateEvent(string state, string @event, AudioSessionAttributes attributes, ILambdaContext context, Request request)
        {
            switch (state)
            {
            case Constants.States.StartMode:
            {
                switch (@event)
                {
                case Constants.Events.LaunchRequest:       return(LaunchRequest(attributes));

                case Constants.Events.PlayAudio:           return(PlayAudio(attributes, true));

                case Constants.Events.Amazon.HelpIntent:   return(Help(attributes));

                case Constants.Events.Amazon.StopIntent:   return(StopCancel(attributes));

                case Constants.Events.Amazon.CancelIntent: return(StopCancel(attributes));

                case Constants.Events.SessionEndedRequest: return(SessionEnded(attributes));

                case Constants.Events.Unhandled:           return(Unhandled(attributes));

                default: throw new InvalidOperationException($"Can't handle state {state} event {@event}");
                }
            }

            case Constants.States.PlayMode:
            {
                switch (@event)
                {
                case Constants.Events.LaunchRequest:          return(LaunchRequest(attributes));

                case Constants.Events.PlayAudio:              return(PlayAudio(attributes, false));

                case Constants.Events.Amazon.NextIntent:      return(NextAudio(attributes));

                case Constants.Events.Amazon.PreviousIntent:  return(PreviousAudio(attributes));

                case Constants.Events.Amazon.PauseIntent:     return(StopAudio(attributes));

                case Constants.Events.Amazon.StopIntent:      return(StopAudio(attributes));

                case Constants.Events.Amazon.CancelIntent:    return(StopAudio(attributes));

                case Constants.Events.Amazon.ResumeIntent:    return(PlayAudio(attributes, false));

                case Constants.Events.Amazon.LoopOnIntent:    return(LoopAudio(attributes, true));

                case Constants.Events.Amazon.LoopOffIntent:   return(LoopAudio(attributes, false));

                case Constants.Events.Amazon.ShuffleOnIntent: return(ShuffleAudio(attributes, true));

                case Constants.Events.Amazon.ShuffleOffInten: return(ShuffleAudio(attributes, false));

                case Constants.Events.Amazon.StartOverIntent: return(StartOverAudio(attributes));

                case Constants.Events.Amazon.HelpIntent:      return(HelpWhilePlaying(attributes));

                case Constants.Events.SessionEndedRequest:    return(SessionEnded(attributes));

                case Constants.Events.Unhandled:              return(UnhandledWhilePlaying(attributes));

                // Remote controller handlers
                case Constants.Events.PlayCommandIssued:      return(PlayAudio(attributes, false));

                case Constants.Events.PauseCommandIssued:     return(StopAudio(attributes));

                case Constants.Events.NextCommandIssued:      return(NextAudio(attributes));

                case Constants.Events.PreviousCommandIssued:  return(PreviousAudio(attributes));

                // Audio events
                case Constants.Events.Audio.PlaybackStarted:
                {
                    attributes.PlaybackFinished = false;
                    attributes.Index            = GetIndexFromToken(attributes, ((AudioPlayerRequest)request).Token);
                    return(Speech.GetContinueResponse());
                }

                case Constants.Events.Audio.PlaybackFinished:
                {
                    attributes.PlaybackFinished = true;
                    attributes.EnqueuedToken    = -1;
                    return(Speech.GetContinueResponse());
                }

                case Constants.Events.Audio.PlaybackStopped:
                {
                    attributes.Index = GetIndexFromToken(attributes, ((AudioPlayerRequest)request).Token);
                    attributes.OffsetInMilliseconds = ((AudioPlayerRequest)request).OffsetInMilliseconds;
                    return(Speech.GetContinueResponse());
                }

                case Constants.Events.Audio.PlaybackNearlyFinished:
                    return(PlaybackNearlyFinishedAudio(attributes));

                case Constants.Events.Audio.PlaybackFailed:
                {
                    _logger.LogLine($"Playback failed: {((AudioPlayerRequest)request).Error}");
                    return(Speech.GetContinueResponse());
                }

                default: throw new InvalidOperationException($"Can't handle state {state} event {@event}");
                }
            }

            case Constants.States.ResumeDecisionMode:
            {
                switch (@event)
                {
                case Constants.Events.LaunchRequest:
                case Constants.Events.Amazon.HelpIntent:
                    return(Speech.GetAskResponse(
                               $"You were listening to episode {attributes.Index + 1}. Would you like to resume?",
                               "You can say yes to resume or no to play from the top."));

                case Constants.Events.Amazon.YesIntent: return(PlayAudio(attributes, false));

                case Constants.Events.Amazon.NoIntent: return(StartOverAudio(attributes));

                case Constants.Events.Amazon.StopIntent:
                case Constants.Events.Amazon.CancelIntent:
                    return(StopAudio(attributes));

                case Constants.Events.SessionEndedRequest: return(SessionEnded(attributes));

                case Constants.Events.Unhandled: return(UnhandledWhilePlaying(attributes));

                default: throw new InvalidOperationException($"Can't handle state {state} event {@event}");
                }
            }
            }

            throw new InvalidOperationException($"Can't handle state {state} event {@event}");
        }