4

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?

Roel Vermeulen
  • 594
  • 7
  • 15
  • Possible duplicate of [Javascript: Can you read the systems volume?](http://stackoverflow.com/questions/5368596/javascript-can-you-read-the-systems-volume) – Sterling Archer Apr 16 '17 at 18:57

1 Answers1

5

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.

anon
  • 154
  • 9
  • Thanks for the clarification on the difference between Ringers/Alerts and General Audio. I guess then I will continue to play the sounds as normal, and it is up to the user to lower his General audio volume if he doesn't want web pages to make sounds. I guess we cannot ask Javascript to play sounds in the Ringers/Alerts category instead of the General audio? – Roel Vermeulen Apr 17 '17 at 23:03
  • 1
    Unfortunately, only native iOS apps have that level of control. JavaScript can't control the audio "classification." You can read more about Apple's audio guidelines for apps if that interests you [here](https://developer.apple.com/ios/human-interface-guidelines/interaction/audio/) and [here](https://developer.apple.com/reference/audiotoolbox/system_sound_services) – anon Apr 18 '17 at 01:36