Web Audio Touch Unlock
Unlocking Web Audio - the smarter way
On iOS, the Web Audio API requires sounds to be triggered from an explicit user action, such as a tap, before any sound can be played on a webpage.
This method fixes the issue without you even having to think about it, you just pass your AudioContext
instance to it and you're good to go!
You can read more about the issue and how this method handles it in this article.
Try it out here.
Installation
npm install web-audio-touch-unlock --save
Usage
JavaScript
var webAudioTouchUnlock = ; var context = new windowAudioContext || windowwebkitAudioContext; ; // Do all your sound related stuff here// as you normally would like if the sound// was never locked// ..var source = context;sourcebuffer = buffer;source;sourcestart;// ...
TypeScript
; ; webAudioTouchUnlockcontext .then,; // Do all your sound related stuff here // as you normally would like if the sound // was never locked// ...;source.buffer = buffer;source.connectcontext.destination;source.start;// ...
License
The MIT License (MIT), Copyright 2017 Pavle Goloskokovic