Skip to content

Latest commit

 

History

History
96 lines (61 loc) · 2.37 KB

File metadata and controls

96 lines (61 loc) · 2.37 KB

Learn more about how to build Alexa AudioPlayer Skills with the Jovo Framework.

Introduction to AudioPlayer Skills

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

Features

Play a File

play(url, token, playBehavior)

// Start playing a file from the beginning
this.alexaSkill().audioPlayer().setOffsetInMilliseconds(0)
    .play(url, token)
    .tell(speech);

Enqueue

this.alexaSkill().audioPlayer().enqueue(url, token)

Stop

this.alexaSkill().audioPlayer().stop();

AudioPlayer Directives

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.