简体   繁体   中英

Can Javascript detect if a mobile device is muted?

My website is currently playing sounds when the user answers a question right/wrong. But I notice that on my tablet (iPad) and mobile (iPhone) it plays the sounds even though I put it in silence mode. And I don't want the phone/tablet to play sounds when the user has clearly set their device in silent mode (the Ringer). So, can I detect whether a device is muted/silenced and then not play any sounds? I tested on Safari and Chrome, and it always plays the sound, irrespective of the Ringer's state.

EDIT: If it is not possible to read this information, then my question would be if there is a way to play sounds that DOES respect the user's muting preferences? I am using jQuery's $("#correctsound").trigger('play') , and clearly this doesn't respect those settings. Do we have a different way to play sounds that takes these settings into account?

The simple answer to your question is no . Web pages don't have access to that kind of information about the client. More info here: Javascript: Can you read the systems volume? Furthermore, it is important to note that iOS has different volume settings for ringers and for media, according to Macworld :

The key to mastering volume adjustment is understanding that most of the sounds on your device fall into one of two categories. General audio includes music and other media, and the voice volume on the iPhone and for FaceTime on all devices. The “ringers and alerts” category includes not only the iPhone ringer, but also: FaceTime rings; Clock app alarms; notifications and individual app alerts; keyboard clicks; and miscellaneous app sounds like the whoosh of sending Mail.

In other words, if a user wants to mute audio coming from web pages, they should mute the media volume. Ringer volume has nothing to do with web pages, so putting your phone in "silent" mode is only meant to affect the ringer volume. If you need help changing your device's volume settings, check out How can I lower the media volume on my iPhone when no media are playing? on the Apple Stack Exchange.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM