Last active
March 26, 2018 12:58
-
-
Save jkelvie/05f7a20b3019fb83558bd87d27f176d8 to your computer and use it in GitHub Desktop.
Playing Audio With The AudioPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Plays a particular track, from specific offset | |
* @param audioURL The URL to play | |
* @param offsetInMilliseconds The point from which to play - we set this to something other than zero when resuming | |
*/ | |
SimplePlayer.prototype.play = function (audioURL, offsetInMilliseconds) { | |
var response = { | |
version: "1.0", | |
response: { | |
shouldEndSession: true, | |
directives: [ | |
{ | |
type: "AudioPlayer.Play", | |
playBehavior: "REPLACE_ALL", // Setting to REPLACE_ALL means that this track will start playing immediately | |
audioItem: { | |
stream: { | |
url: audioURL, | |
token: "0", // Unique token for the track - needed when queueing multiple tracks | |
expectedPreviousToken: null, // The expected previous token - when using queues, ensures safety | |
offsetInMilliseconds: offsetInMilliseconds | |
} | |
} | |
} | |
] | |
} | |
} | |
this.context.succeed(response); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment