I'm playing around with the Alexa-SDK for NodeJS and ran into trouble with the AudioPlayer and its controls.
The Problem:
When I start an audio stream with the following code snippet, it starts playing (as intended), but there is no chance of stopping the playback again with the built-in "AMAZON.StopIntent" or any other intent available.
Alexa answers with something like: "An error occurred while handling a request within your service." and keeps playing until the track was played to the end.
this.response.audioPlayerPlay(behavior, url, token, expectedPreviousToken, offsetInMilliseconds)
this.emit(':responseReady');
Here are my handlers for a better overview. I took the structure from the skill-sample-nodejs-audio-player:
var stateHandlers = {
startModeIntentHandlers : Alexa.CreateStateHandler(constants.states.START_MODE, {
'LaunchRequest': function() {
this.handler.state = constants.states.PLAY_OCCASION_MODE;
this.emit(':ask', 'Welcome, say yes to start the playback.','Say yes to start the playback');
},
'AMAZON.StopIntent': function() {
this.response.audioPlayerStop();
this.emit(':tell', 'See you next Time!');
},
'AMAZON.CancelIntent': function() {
this.emit(':tell', 'See you next Time!');
},
'SessionEndedRequest': function () {
this.emit(':tell', 'See you next Time!');
}
}),
playOccasionModeIntentHandlers : Alexa.CreateStateHandler(constants.states.PLAY_OCCASION_MODE, {
'LaunchRequest': function () {
this.emit('LaunchRequest'); // Uses the handler in newSessionHandlers
},
'AMAZON.YesIntent': function() {
this.handler.state = constants.states.PLAY_OCCASION_MODE;
this.response.speak('Lets go. Here comes your Podcast.');
this.response.audioPlayerPlay('REPLACE_ALL', 'https://feeds.soundcloud.com/stream/274166909-amazon-web-services-306355661-aws-podcast-episode-139.mp3', 'earlybird', null, 0);
this.emit(':responseReady');
},
'AMAZON.NoIntent': function() {
this.emit(':tell', 'See you next Time!');
},
'AMAZON.StopIntent': function() {
this.response.audioPlayerStop();
this.response.speak('See you next Time!');
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function() {
this.emit(':tell', 'See you next Time!');
},
'SessionEndedRequest': function () {
this.emit(':tell', 'See you next Time!');
},
'Unhandled': function() {
this.emit(':tell', 'See you next Time!');
}
}),
};
EDIT:
If I add an "Unhandled" Function to the START_MODE
state, Alexa will always answer with this one and ignores the StopIntent completely.
It's a first workaround, but when it comes to more advanced functions like playing the next song or pausing the playback the problem comes back.
'Unhandled': function() {
this.response.audioPlayerStop();
this.response.speak('Unhandled!');
this.emit(':responseReady');
}
EDIT2:
A Solution seems to be found. I have not added the AMAZON.PauseIntent
which takes also "Alexa, stop" commands. By just adding it, it seems to work more or less right now.
'AMAZON.PauseIntent' : function () {
this.response.audioPlayerStop();
this.response.speak('Paused. See you next time!');
this.emit(':responseReady');
},