play silent audio for browsers that don't implement resume

this jumpstarts the AudioContext
This commit is contained in:
tambien 2018-05-17 18:38:40 -04:00
parent 8b92b7469b
commit 0f67791315
2 changed files with 11 additions and 5 deletions

View file

@ -18,6 +18,12 @@ define(["Tone/core/Tone", "Tone/shim/OfflineAudioContext"], function(Tone){
//not functionally equivalent
if (!AudioContext.prototype.resume){
AudioContext.prototype.resume = function(){
//play some silent audio to jumpstart the context
var buffer = this.createBuffer(1, 1, this.sampleRate);
var source = this.createBufferSource();
source.buffer = buffer;
source.connect(this.destination);
source.start(0);
return Promise.resolve();
};
}