Giter Site home page Giter Site logo

feross / unmute-ios-audio Goto Github PK

View Code? Open in Web Editor NEW
114.0 5.0 8.0 22 KB

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

Home Page: https://bitmidi.com

License: MIT License

JavaScript 100.00%
nodejs javascript web web-audio audio ios mute safari

unmute-ios-audio's Introduction

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.

unmute-ios-audio's People

Contributors

chrisguttandin avatar feross avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

unmute-ios-audio's Issues

iOS detection issue

Hi Feross,

Thanks for making this utility which makes it so easy to solve the annoying ringer mute problem! I seem to be affected by one small issue with it:

I'm using an iPhone Xs running iOS 13.7 and navigator.userAgent returns Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15. Thus it doesn't seem to work (no errors, but still muted), until I replace
const isIos = /iPhone|iPad|iPod/.test(navigator.userAgent) && AudioContext != null
with
const isIos = AudioContext != null
then, it works great.

Is the latter not a sufficient check, and/or are there practical consequences for running the full body of unmuteIosAudio when it isn't needed?

Correct CSP Rules

Hi,

I would like to understand exactly what CSP rule is required for the mute to work. Unfortunately no error is logged if the CSP rule does not apply. Therefore we have to set default-src data:; which is not optimal.

Thanks for implementing and maintaining unmute-ios-audio!

Best,
Daniel

Does it still work with current iOS versions?

We've been using that package for a while and it worked well. However, with current iOS versions it doesn't seem to work anymore. At least with our application.

Version 3.1.0 works with old versions of iOS like 12.5.3 (on an iPhone 6). Version 3.2 and 3.3 do not work there as well.

On newer iOS 14.5 or iPad Os etc. our app suddenly doesn't work together with this package using any version of it. Can you confirm, that it still should basically work (... and that the issue may be the setup in our project)?

Thank you very much.

Website Displays On User Lock Screen

Thanks for the great package, I'm using it with wave surfer to add some audio players to my website.

It solves the issue of playback when the iPhone is on "silence" mode -- however it also makes the website appear as a playback source on the user's Lock Screen.

Not a huge issue -- but is there any way to avoid this your team may know?

Thanks,

Jake

TypeScript support

Hi Feross,

would you be interested in adding TypeScript support? I would be happy to create a pull request with a .dts file in case you are. Just let me know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.