Keeping track of position in long-form audio

amazon-alexa

#1

Hi, I would like to build a skill that plays long-form audiobooks (on Alexa). I am interested in the possibilities to keep track of the current position of listening. So if someone is 30 min into a 60 min piece and stops, that I can resume it at the same position he/she calls the skill next time (even if they have used Alexa for other things in the mean time).

Is that possible? Can I get the current position when a cancel or stop intend is called? Is that the way to do it?


#2

You can do this with the offset. Here’s the relevant part of the Alexa Audioplayer template:

PauseIntent() {
    this.$alexaSkill.$audioPlayer.stop();

    // Save offset to database
    this.$user.$data.offset = this.$alexaSkill.$audioPlayer.getOffsetInMilliseconds();
    this.tell('Paused!');
},