本文介绍了Javascript可以检测移动设备是否静音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户回答正确/错误的问题时,我的网站正在播放声音。但我注意到,即使我把它置于静音模式,我的平板电脑(iPad)和手机(iPhone)也能播放声音。当用户将设备设置为静音模式(Ringer)时,我不希望手机/平板电脑播放声音。那么,我可以检测设备是静音/静音然后不播放任何声音吗?我在Safari和Chrome上测试过,无论Ringer的状态如何,它都会播放声音。

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.

编辑:如果不可能阅读这些信息,那么我的问题是,是否有一种方法可以播放尊重用户静音偏好的声音?我正在使用jQuery的 $(#correctsound)。触发器('play'),显然这并不尊重这些设置。我们是否有不同的方式来播放将这些设置考虑在内的声音?

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?

推荐答案

您问题的简单答案是没有即可。网页无法访问有关客户端的此类信息。更多信息:此外,重要的是要注意iOS对于铃声和媒体有不同的音量设置,根据:

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:

换句话说,如果如果用户想要静音来自网页的音频,则应将媒体音量设为静音。 铃声音量与网页无关,因此将手机置于静音模式只会影响铃声音量。如果您需要帮助更改设备的音量设置,请查看 Apple Stack Exchange。

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.

这篇关于Javascript可以检测移动设备是否静音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 06:34