Skip to content

Instantly share code, notes, and snippets.

@pavle-goloskokovic
Created January 20, 2018 12:46
Show Gist options
  • Save pavle-goloskokovic/ceaa0945de79f3093790aec01985480f to your computer and use it in GitHub Desktop.
Save pavle-goloskokovic/ceaa0945de79f3093790aec01985480f to your computer and use it in GitHub Desktop.
Now you can use this function anywhere in your code like this
webAudioTouchUnlock(context).then(function (unlocked)
{
if(unlocked)
{
// AudioContext was unlocked from an explicit user action,
// sound should start playing now
}
else
{
// There was no need for unlocking, devices other than iOS
}
},
function(reason)
{
console.error(reason);
});
@pavle-goloskokovic
Copy link
Author

I’ve created an npm package called web-audio-touch-unlock
that exposes this method and makes it easy to use in your own projects.
Just pass your AudioContext instance to it and you’re good to go!

You can try it out yourself here.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment