Skip to content

Enable/unmute WebAudio on iOS, even while mute switch is on

License

Notifications You must be signed in to change notification settings

feross/unmute-ios-audio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unmute-ios-audio travis npm downloads javascript style guide

Enable/unmute WebAudio on iOS, even while mute switch is on

On Safari for iOS, audio is allowed to play when the device's mute switch is enabled, but only for HTML5 audio tags, and not for Web Audio. This module fixes that and adds consistency and reliability to web audio in Safari. Note that a "user activation" in the form of a click or touchstart event is still required to play audio. This package merely unmutes Web Audio even while the mute switch is enabled on the device.

This package works by playing a short, silent sound using an <audio> tag and an AudioContext whenever the user interacts with the page. That's it.

Built for and used on BitMidi, a free MIDI database. Works in the browser with browserify!

install

npm install unmute-ios-audio

usage

const unmuteAudio = require('unmute-ios-audio')

// Call once, as early as possible in the page lifecycle
unmuteAudio()

API

unmuteAudio()

Enable/unmute the WebAudio API on iOS, even while the mute switch is on.

Call this function as early as possible so that the user event handlers can be registered and you don't miss any user interactions which could have been used to unmnute the audio.

thanks

The techniques used within this package were inspired by:

license

MIT. Copyright (c) Feross Aboukhadijeh.