question

TruJared avatar image
TruJared asked

Why is AMAZON.StopIntent working but AMAZON.CancelIntent not working to stop the audio when both are in the same handler?

To pass certification this skill has to stop playing audio when the user says Alexa cancel or Alexa stop.
I can not get this to work, no matter what I do. I'm hoping someone has some insight here. I have tried removing all references of AMAZON.CancelIntent from both handlers and I have tried keeping the cancel intent in only one handler as well. No matter what I do the cancel intent will not stop the audio.

However, I can verify that the codes works because the AMAZON.StopIntent works correctly. I'm really at at a loss here. Below is the code. The cancel intent is in my language model as well.

What am I not seeing. Thanks in advance for your help!

// Stops playback

const StopPlaybackHandler = {
  async canHandle(handlerInput) {
    const playbackInfo = await getPlaybackInfo(handlerInput);
    const request = handlerInput.requestEnvelope.request;

    return (
      playbackInfo.inPlaybackSession &&
      request.type === 'IntentRequest' &&
      (request.intent.name === 'AMAZON.StopIntent' || 
	request.intent.name === 'AMAZON.CancelIntent')
    );
  },
  handle(handlerInput) {
    return controller.stop(handlerInput);
  },
};

// Controller object

const controller = {
  ...
  stop(handlerInput) {
    return handlerInput
	.responseBuilder
	.addAudioPlayerStopDirective()
	.getResponse();
  },
...

// Handles canceling and stopping when no audio playback
// probably not relevant to this problem, but just in case
const CancelAndStopIntentHandler = {
  canHandle(handlerInput) {
    return (
      handlerInput.requestEnvelope.request.type === 'IntentRequest' &&
      (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent' ||
        handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent')
    );
  },
  handle(handlerInput) {
    console.log(`user stopped playback, or canceled some request`);
    return handlerInput.responseBuilder.speak('').getResponse();
  },
};
alexa skills kitaudioplayerbuilt-in librarycontrollersdk v2
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

TruJared avatar image
TruJared answered

Got it sorted. Here's the post that helped me. Not sure why this fixed it but it did.

https://forums.developer.amazon.com/questions/139543/why-does-saying-alexa-stop-during-audio-playback-c.html

and the code

const PausePlaybackHandler = {
  async canHandle(handlerInput) {
    const playbackInfo = await getPlaybackInfo(handlerInput);
    const request = handlerInput.requestEnvelope.request;

    return (
      playbackInfo.inPlaybackSession &&
      request.type === 'IntentRequest' &&
      (request.intent.name === 'AMAZON.StopIntent' ||
        request.intent.name === 'AMAZON.CancelIntent' ||
        request.intent.name === 'AMAZON.PauseIntent')
    );
  },
  handle(handlerInput) {
    return controller.stop(handlerInput);
  },
};


10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.