Skip to content

Instantly share code, notes, and snippets.

@jkelvie
Last active March 26, 2018 12:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkelvie/05f7a20b3019fb83558bd87d27f176d8 to your computer and use it in GitHub Desktop.
Save jkelvie/05f7a20b3019fb83558bd87d27f176d8 to your computer and use it in GitHub Desktop.
Playing Audio With The AudioPlayer
/**
* 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