【发布时间】:2012-07-15 09:52:06
【问题描述】:
我经常读到无法使用Web Audio API 暂停/恢复音频文件。
但现在我看到了example,他们实际上使暂停和恢复它成为可能。我试图弄清楚他们是怎么做到的。我想也许source.looping = false是关键,但它不是。
现在我的音频总是从头开始重新播放。
这是我当前的代码
var context = new (window.AudioContext || window.webkitAudioContext)();
function AudioPlayer() {
this.source = context.createBufferSource();
this.analyser = context.createAnalyser();
this.stopped = true;
}
AudioPlayer.prototype.setBuffer = function(buffer) {
this.source.buffer = buffer;
this.source.looping = false;
};
AudioPlayer.prototype.play = function() {
this.source.connect(this.analyser);
this.analyser.connect(context.destination);
this.source.noteOn(0);
this.stopped = false;
};
AudioPlayer.prototype.stop = function() {
this.analyser.disconnect();
this.source.disconnect();
this.stopped = true;
};
有人知道该怎么做才能让它发挥作用吗?
【问题讨论】:
标签: javascript html google-chrome html5-audio web-audio-api