0

I'm trying to implement the Play functionality of the Alexa to play an mp3 file I get from an API call. I get the data back fine, and the speak directive does include the data from the API response, so I know the call worked, but the file itself never plays.

I am testing with a physical echo device.

The Cloudwatch logs are not super-helpful (is there a better place where I can see the whole stack trace?), but I do see an error there of:

Unable to find a suitable request handler.

Followed by an end of session with undefined.

Here's the code for my implementation:

API call:

const getEpisode = uri => new Promise(
  (resolve, reject) => {
    httpRequest({
      method: 'GET',
      uri,
      json: true,
      headers: {
        'X-API-KEY': key,
      },
    }).then(data => {
      console.log(data);
      return resolve(data);
    })
      .catch(err => reject(new Error(err)));
  }
);

PlayIntent:

const PlayIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest' ||
        (handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'PlayIntent') ||
        (handlerInput.requestEnvelope.request.type === 'IntentRequest'
        && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ResumeIntent');
  },
  async handle(handlerInput) {
    const uri = `${endpoint}/most_recent/amazon`;
    console.log(uri);
    const data = await getEpisode(uri);
    console.log("before setting response");
    return handlerInput.responseBuilder
      .speak(`Playing episode ${data.episode_title}`)
      .addAudioPlayerPlayDirective('REPLACE_ALL', data.episode_url, data.episode_title, 0, null, null)
      .withShouldEndSession(true)
      .getResponse()
  },
};

Any idea where I'm going wrong?

wonderv
  • 143
  • 1
  • 7

1 Answers1

0

The addAudioPlayerPlayDirective takes 5 parameters:

playBehavior - 'REPLACE_ALL'

url - data.episode_url

enqueueToken - data.episode_title

offsetInMilliseconds - `0`

expectedPreviousToken - `null`

.addAudioPlayerPlayDirective('REPLACE_ALL', data.episode_url, data.episode_title, 0, null, null)

As you can see, you have an extra parameter null being passed on. Remove it.

bal simpson
  • 186
  • 8
  • Actually, according to [this](https://ask-sdk-for-nodejs.readthedocs.io/en/latest/Building-Response.html?highlight=addAudioPlayerPlayDirective) the full signature for `addAudioPlayerPlayDirective` is: `addAudioPlayerPlayDirective(playBehavior: interfaces.audioplayer.PlayBehavior, url: string, token: string, offsetInMilliseconds: number, expectedPreviousToken?: string, audioItemMetadata? : AudioItemMetadata);` Either way, as stated in my comment above, it does seem to work in Echo Show (and someone at Amazon tested it on a Dot and it worked for them too), so maybe the Dot I have is faulty. – wonderv Dec 07 '18 at 22:10
  • oh ok. I have a custom Radio Skill and I am not using the last parameter and it works just fine. – bal simpson Dec 08 '18 at 05:57