我經常讀到,無法使用Web Audio API暫停/恢復音頻文件。
但現在我看到一個example他們實際上可以暫停和恢復它。我試圖弄清楚他們是怎麼做到的。我想也許source.looping = false
是關鍵,但事實並非如此。
現在我的音頻始終從頭播放。Web音頻API從暫停恢復
這是我當前的代碼
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;
};
有誰知道做什麼,得到它的工作?
那麼他在示例中沒有使用'noteGrainOn()'(儘管如此,仍然無法弄清楚他是如何做到的)。但無論如何,這是一種魅力,所以我將把它作爲一個被接受的答案。謝謝:) – 2012-07-16 14:59:49
noteGrainOn()現在已經在spec中重命名了,就像noteOn() - 都是現在的play(),有或沒有grain偏移參數。儘管如此,還沒有看到這種支持。 – LeeGee 2012-10-03 12:53:50
它實際上是'開始'(有或沒有參數'開始(howSoonRelativeToCurrentTime,fromSecondInBuffer,forDuration)'),它似乎在鉻金絲雀工作 – 2013-01-27 10:12:43