Can Javascript detect if a mobile device is muted?

混江龙づ霸主 提交于 2019-12-01 12:48:43

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/43440882/can-javascript-detect-if-a-mobile-device-is-muted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!