start-web-audio
v1.4.0
Published
chore function for starting web audio in mobile Safari
Downloads
3
Readme
startWebAudio
chore function for starting web audio in mobile Safari
Installation
npm install start-web-audio
downloads:
API
startWebAudio(audioContext, [ elem, requireUserAction, callback ]): void
- attach event listeners to
elem
for starting Web Audio API audioContext: AudioContext
elem: EventTarget
- a target of event listener - default: window
requireUserAction: boolean
- require user action - default: false
- this option is useful, when want to use the same workflow in all devices.
callback: function
- called when Web Audio API has been started - default: noop
- attach event listeners to
Usage
var audioContext = new AudioContext();
startWebAudio(audioContext, function() {
console.log("web audio is now available");
});
setInterval(function() {
var oscillator = audioContext.createOscillator();
oscillator.start(audioContext.currentTime);
oscillator.stop(audioContext.currentTime + 0.1);
oscillator.connect(audioContext.destination);
}, 1000);
License
MIT