jovotech / jovo-framework

🔈 The React for Voice and Chat: Build Apps for Alexa, Messenger, Instagram, the Web, and more
https://www.jovo.tech
Apache License 2.0
1.67k stars 310 forks source link

AudioPlayer.PlaybackNearlyFinished triggers too early #244

Closed kevinApplaud closed 6 years ago

kevinApplaud commented 6 years ago

I'm submitting a...

Expected Behavior

I need to play a list of mp3 urls.

Current Behavior

PlaybackNearlyFinished triggers too early, I need to play a list of mp3 files. But It only plays them for 1 sec and then plays next one for 1 sec etc...

Code

"use strict";

// =================================================================================
// App Configuration
// =================================================================================

const { App } = require("jovo-framework");

const config = {
  logging: true,
  intentMap: {
    "AMAZON.PauseIntent": "PauseIntent",
    "AMAZON.ResumeIntent": "ResumeIntent"
  }
};

const app = new App(config);
let mp3Arr;

let currentMp3Count = 0;
app.setHandler({
  LAUNCH: function() {
    this.toIntent("PlayIntent");
  },

  PlayIntent: function() {
    mp3Arr = [
      "https://s3.amazonaws.com/jovo-songs/song1.mp3",
      "https://s3.amazonaws.com/jovo-songs/song1.mp3"
    ];
    this.alexaSkill()
      .audioPlayer()
      .setOffsetInMilliseconds(0)
      .play(mp3Arr[currentMp3Count], "token")
      .tell("Playing news");
  },

  PauseIntent: function() {
    this.alexaSkill()
      .audioPlayer()
      .stop();
    this.tell("Paused!");
  },

  ResumeIntent: function() {
    this.alexaSkill()
      .audioPlayer()
      .setOffsetInMilliseconds(0)
      .play(news[currentNews].url, "token")
      .tell("Resuming!");
  },

  StopIntent: function() {
    console.log("StopIntent");
    this.endSession();
  },

  AUDIOPLAYER: {
    "AudioPlayer.PlaybackStarted": function() {
      console.log("AudioPlayer.PlaybackStarted");
      this.endSession();
    },

    "AudioPlayer.PlaybackNearlyFinished": function() {
      console.log("AudioPlayer.PlaybackNearlyFinished");
      currentMp3Count++;

      if (currentMp3Count < mp3Arr.length) {
        this.alexaSkill()
          .audioPlayer()
          .setOffsetInMilliseconds(0)
          .play(mp3Arr[currentMp3Count], "token");
      } else {
        currentMp3Count = 0;
        this.toIntent("StopIntent");
      }
    },

    "AudioPlayer.PlaybackFinished": function() {
      console.log("AudioPlayer.PlaybackFinished");
      this.endSession();
    },

    "AudioPlayer.PlaybackStopped": function() {
      console.log("AudioPlayer.PlaybackStopped");
      this.endSession();
    }
  }
});

module.exports.app = app;

Your Environment

jankoenig commented 6 years ago

Hi @kevinApplaud,

We can't do anything about requests being triggered too early, as they're coming from the Alexa platform, not from the Jovo Framework. Are you using an Echo Spot for testing? We noticed a few months ago that this device isn't as reliable as others regarding audioplayer requests.

Here are a few things I'd suggest:

Closing this as it's not a bug. Let me know if you have any more questions