Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioPlayer functionality #88

Closed
wants to merge 6 commits into from
Closed

Conversation

wschaeferiii
Copy link

@wschaeferiii wschaeferiii commented Nov 14, 2016

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.

@coveralls
Copy link

Coverage Status

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

@wschaeferiii wschaeferiii reopened this Nov 14, 2016
@wschaeferiii wschaeferiii changed the title merge working code AudioPlayer functionality Nov 14, 2016
@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@coveralls
Copy link

Coverage Status

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

@wschaeferiii
Copy link
Author

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

@chrisdeely
Copy link

@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?

@wschaeferiii
Copy link
Author

@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.

@dblock
Copy link
Collaborator

dblock commented Dec 16, 2016

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

@fremail
Copy link
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 :)

@dblock
Copy link
Collaborator

dblock commented Dec 19, 2016

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

@fremail
Copy link
Contributor

fremail commented Dec 19, 2016

@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.

@fremail
Copy link
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

@dblock
Copy link
Collaborator

dblock commented Dec 22, 2016

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

@dblock
Copy link
Collaborator

dblock commented Dec 26, 2016

Closed via https://github.com/matt-kruse/alexa-app/pull/92, thanks @fremail for finishing this!

@dblock dblock closed this Dec 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants