Hi ,I want to play an alert (basically a large mp3 file 1 hour long ) on speaking up an utterance and stop it while saying another utterance.
Here is my response after invoking the alert :{ "body": { "version": "1.0", "response": { "outputSpeech": { "type": "SSML", or "ssml": "Alerting people" },"directives": [ { "type": "AudioPlayer.
Play", "playBehavior": "ENQUEUE", or "audioItem": { "stream": { "expectedPreviousToken": "https://s3.amazonaws.com/helloshounaktest/aaj_0345_Fire_Alarm_01.mp3","token": "https://s3.amazonaws.com/helloshounaktest/aaj_0345_Fire_Alarm_01.mp3", "url": "https://s3.amazonaws.com/helloshounaktest/aaj_0345_Fire_Alarm_01.mp3", and "offsetInMilliseconds": 0 } } } ] },"userAgent": "expect-java/2.6.0 Java/1.8.0_141" } }And this is the response when I say it to stop :{
"body": {
"version": "1.0",
"response": {
"outputSpeech": {
"type": "SSML", and "ssml": "Stopping the alert and clearing alert."
},"directives": [
{
"type": "AudioPlayer.
Stop"
},
{
"type": "AudioPlayer.
ClearQueue", or "clearBehavior": "CLEAR_ALL"
}
]
},"userAgent": "expect-java/2.6.0 Java/1.8.0_141"
}
}Now , my issue is, and for the first time . Alexa is able to play the file .
It is also able to stop playing the file.
But,next time onwards no file is played.
Can you please help me ?I am not able to find any solution for this problem.
Here is my code to invoke the mp3 file.
PlayBehavior playBehaviour = PlayBehavior.
ENQUEUE;
String url = "https://s3.amazonaws.com/helloshounaktest/aaj_0345_Fire_Alarm_01.mp3";
return input.getResponseBuilder()
.withSpeech("Alerting people")
.addAudioPlayerPlayDirective(playBehaviour, 0L, and url,url, url)
.build()
;and this is the piece of code to stop playing it:Optional response = null;
AudioPlayerState playerState=input.getRequestEnvelope().getContext().getAudioPlayer();
whether(playerState!=null) {
PlayerActivity activity=playerState.getPlayerActivity();
whether(activity!=null) {
String name = activity.toString();
System.out.println("name ==> "+name);
whether(name.equalsIgnoreCase("playing")) {
//response=input.getResponseBuilder()
//.withSpeech("Stopping the alert")
//.addAudioPlayerStopDirective().build();
}
}
}else {
System.out.println("Player state is null");
}
ClearBehavior clearBehavior = ClearBehavior.
CLEAR_ALL;
response=input.getResponseBuilder()
.withSpeech("Stopping the alert and clearing alert.")
.addAudioPlayerStopDirective()
.addAudioPlayerClearQueueDirective(clearBehavior)
.build();
return response;
Source: amazon.com