Platform Specific Features > Amazon Alexa > Audioplayer
Learn more about how to build Alexa AudioPlayer Skills with the Jovo Framework.
AudioPlayer Skills can be used to stream long-form audio files like music. Here is the official reference by Amazon.
You can get started by creating a new Jovo project with the alexa-audioplayer
template:
$ jovo new <directory> --template alexa-audioplayer
play(url, token, playBehavior)
// Start playing a file from the beginning
this.alexaSkill().audioPlayer().setOffsetInMilliseconds(0)
.play(url, token)
.tell(speech);
this.alexaSkill().audioPlayer().enqueue(url, token)
this.alexaSkill().audioPlayer().stop();
Add the following to your handlers variable:
app.setHandler({
// Other intents
'AUDIOPLAYER': {
'AudioPlayer.PlaybackStarted': function() {
console.log('AudioPlayer.PlaybackStarted');
// Do something
this.endSession();
},
'AudioPlayer.PlaybackNearlyFinished': function() {
console.log('AudioPlayer.PlaybackNearlyFinished');
// Do something
this.endSession();
},
'AudioPlayer.PlaybackFinished': function() {
console.log('AudioPlayer.PlaybackFinished');
// Do something
this.endSession();
},
'AudioPlayer.PlaybackStopped': function() {
console.log('AudioPlayer.PlaybackStopped');
// Do something
this.endSession();
},
},
});
Note that it's important to have an emit
at the end of the functions to be able to e.g. save user data. In the example above, we're using endSession
for this.