简体   繁体   English

Javascript是否可以检测到移动设备是否静音?

[英]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. 但是我注意到即使在静音模式下,在平板电脑(iPad)和手机(iPhone)上,它也会播放声音。 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. 我在Safari和Chrome上进行了测试,无论Ringer的状态如何,它始终可以播放声音。

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. 我使用的是jQuery的$("#correctsound").trigger('play') ,显然这不符合这些设置。 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? 此处提供更多信息: Javascript:您可以阅读系统卷吗? Furthermore, it is important to note that iOS has different volume settings for ringers and for media, according to Macworld : 此外,需要特别注意的是,根据Macworld的说法,iOS对铃声和媒体的音量设置不同:

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. 常规音频包括音乐和其他媒体,以及iPhone和所有设备上FaceTime的语音音量。 The “ringers and alerts” category includes not only the iPhone ringer, but also: FaceTime rings; “铃声和警报”类别不仅包括iPhone铃声,还包括:FaceTime铃声; 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? 如果需要帮助更改设备的音量设置,请查看如何在没有媒体播放时降低iPhone上的媒体音量? on the Apple Stack Exchange. 在Apple Stack Exchange上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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