AudioPlayer functionality #88

Closed
wants to merge 6 commits into
from

Conversation

Projects
None yet
5 participants

wschaeferiii commented Nov 14, 2016 edited

Added Audioplayer functionality to the alexa-app library.

Simply write response.audioPlayerPlay(url, token, playBehavior, offsetInMilliseconds, expectedPreviousToken) and you can play long form audio URL requests with a given url and token. playBehavior defaults to "ENQUEUE_ALL", and offsetInMilliseconds defaults to 0, and expectedPreviousToken defaults to undefined.

Also, added is response.audioPlayerStop() and response.audioPlayerClearQueue(clearBehavior) where clearBehavior defaults to "CLEAR_ALL" .

The request's context object is required in long form audio requests since the session object is not included once the player begins playing, but is copied from the request's session object.

wschaeferiii added some commits Nov 3, 2016

@wschaeferiii wschaeferiii wip, have context object appending with most props 6bdbc64
@wschaeferiii wschaeferiii added audioplayer directives and context object to enable long form a…
…udio using response object
82ec687

Coverage Status

Coverage decreased (-7.2%) to 73.79% when pulling 82ec687 on wschaeferiii:master into 72cd1f7 on matt-kruse:master.

wschaeferiii reopened this Nov 14, 2016

wschaeferiii changed the title from merge working code to AudioPlayer functionality Nov 14, 2016

Coverage Status

Coverage decreased (-7.2%) to 73.79% when pulling 82ec687 on wschaeferiii:master into 72cd1f7 on matt-kruse:master.

@wschaeferiii wschaeferiii eslint
0ace347

Coverage Status

Coverage decreased (-8.4%) to 72.581% when pulling 0ace347 on wschaeferiii:master into 72cd1f7 on matt-kruse:master.

@wschaeferiii wschaeferiii added unit tests
d3a2488

Coverage Status

Coverage decreased (-7.5%) to 73.494% when pulling d3a2488 on wschaeferiii:master into 72cd1f7 on matt-kruse:master.

@wschaeferiii wschaeferiii eslint
d83dc1b

Coverage Status

Coverage decreased (-7.5%) to 73.494% when pulling d83dc1b on wschaeferiii:master into 72cd1f7 on matt-kruse:master.

@wschaeferiii wschaeferiii added more tests
fdc55c1

Coverage Status

Coverage increased (+1.8%) to 82.8% when pulling fdc55c1 on wschaeferiii:master into 72cd1f7 on matt-kruse:master.

Alright, sorry for all the failed merges / coverage issues.

@wschaeferiii Nice work here, exactly what I needed. You mentioned being able to play "long form audio", but I noticed that Alexa will continually loop a single section of an HLS live playlist instead of retrieving new segments. Have you experienced this? Are there additional flags to be set and/or intents to handle refreshing a live stream?

@chrisdeely Have you tried listening on the request with type AudioPlayer.PlaybackNearlyFinished sent from Alexa to your skill? Here's the Amazon documentation on it , however I am not sure on how to implement it into the library for easy use.

Collaborator

dblock commented Dec 16, 2016

This looks good. It needs a README and CHANGELOG update, please.

Contributor

fremail commented Dec 19, 2016

@wschaeferiii Thank you for working on this! AudioPlayer interface is really useful!
Handling AudioPlayer events in pre isn't handy and the code is pretty messy.

What about adding a method like app.intent - app.audioPlayer(event, func) to handle the events: PlaybackStarted, PlaybackFinished, PlaybackStopped, PlaybackNearlyFinished, PlaybackFailed.

I imagine the code would be similar to intent implementation :)

Collaborator

dblock commented Dec 19, 2016

@fremail I think that would be better. Want to try an alternate implementation?

Contributor

fremail commented Dec 19, 2016 edited

@wschaeferiii Using code from your branch I got an error.

I have an app uploaded to Lambda.

The error is caused on getting AudioPlayer events. I got for these events: AudioPlayer.PlaybackStarted, AudioPlayer.PlaybackNearlyFinished and AudioPlayer.PlaybackFinished.

{
    "errorMessage": "Cannot read property 'new' of undefined",
    "errorType": "TypeError",
    "stackTrace": [
        "new alexa.request (/var/task/node_modules/alexa-app/index.js:219:27)",
        "/var/task/node_modules/alexa-app/index.js:317:18",
        "tryCatcher (/var/task/node_modules/alexa-app/node_modules/bluebird/js/main/util.js:26:23)",
        "Promise._resolveFromResolver (/var/task/node_modules/alexa-app/node_modules/bluebird/js/main/promise.js:483:31)",
        "new Promise (/var/task/node_modules/alexa-app/node_modules/bluebird/js/main/promise.js:71:37)",
        "request (/var/task/node_modules/alexa-app/index.js:316:10)",
        "handler (/var/task/node_modules/alexa-app/index.js:448:8)"
    ]
}

I logged the event in this.handler (index.js:447):

{ 
  version: '1.0', 
  context: { 
    AudioPlayer: { 
      offsetInMilliseconds: 731, 
      token: 'japanese_audio', 
      playerActivity: 'FINISHED' 
    }, 
    System: { 
      application: [Object], 
      user: [Object], 
      device: [Object] 
    } 
  }, 
  request: { 
    type: 'AudioPlayer.PlaybackFinished', 
    requestId: 'amzn1.echo-api.request.fa43da2e-9ea2-4149-bd47-3b077388e5e8', 
    timestamp: '2016-12-19T15:12:08Z', 
    locale: 'en-US', 
    token: 'japanese_audio', 
    offsetInMilliseconds: 731 
  } 
}

Though I think code from master has the same error.

Contributor

fremail commented Dec 19, 2016

It seems the problem is in this:

The session object is included for all standard requests, but it is not included for AudioPlayer or PlaybackController requests.

source

Collaborator

dblock commented Dec 22, 2016

@fremail Will you finish this one up now that #91 is merged? Thanks!

Collaborator

dblock commented Dec 26, 2016

Closed via matt-kruse#92, thanks @fremail for finishing this!

dblock closed this Dec 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment