<p>我们在Github上创建了一个非常简单的项目,展示了使用音频播放器的最简单方法:<br/>
<a href="https://github.com/bespoken/super-simple-audio-player" rel="nofollow noreferrer">https://github.com/bespoken/super-simple-audio-player</a></p>
<p>我们还为它创建了一个writeup:<br/>
<a href="https://bespoken.tools/blog/2017/02/27/super-simple-audioplayer" rel="nofollow noreferrer">https://bespoken.tools/blog/2017/02/27/super-simple-audioplayer</a></p>
<p>该项目演示如何播放曲目,以及暂停和继续。</p>
<p>下面是显示音频文件实际播放的代码:</p>
<pre><code>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);
};
</code></pre>