Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to detect system's volume (sound) and audio jack plugged in

HTML5 has an onboard volume detection.

<video controls width="320" height="176" onvolumechange="alert('The volume has been changed')">

This is for the player only.

Is it possible to detect volume from the system? Say a phone. Can I get volume readings of my phone from the mobile browser?

Or can I use JS to detect if the audio jack is plugged in?

Can Volume level be detected for audio out using GetUserMedia?

like image 453
Cody Raspien Avatar asked Oct 01 '14 20:10

Cody Raspien


1 Answers

Short answer for this is no! This is how web-browsers have been made for a very long time now, and Microsoft/Google/Apple/Mozilla/Opera have done this to avoid exploits through File.IO and such. Actually, we should be thankful for this - as it isolates you computer (with all your personal stuff) from the web-application (which might be hosted on a server with hostile intentions).

Actually, there is one way you could do this, but it would only work for IE users - and the answer is activeX plugins. Now, you could make your javascript create such a plugin and communicate with it - but who knows if activeX will be supported by IE in the future.

So per se, there is no way this is achievable with HTML5/Javascript alone - just think of the browser as the OS on which your web-app is running. So Google, Microsoft etc + the rest of the people who decides the HTML5 standards are the ones who decides how much access the developer gets. Camera hardware, GPS hardware etc. we do get to access, but we are not allowed to do whatever we want with that hardware - its not always the developers choice.

like image 140
Amund Midtskog Avatar answered Nov 18 '22 14:11

Amund Midtskog