Javascript Sound Detection

Is there a way to determine if a particular page is making noise with jscript? Some kind of environment variable or something that keeps track of column status? I am trying to write a script that places an icon in the title of a tab if this tab makes a sound.

+4
source share
4 answers

No, It is Immpossible.

Many plugins can make sound, and they all do it their own way. There is no trick here.

Perhaps on Vista / 7, where in practice application usage is tracked, and when using a browser such as Chrome that does a separate process for each page, you might be more fortunate. This will include figuring out which processes are playing sound, and then figuring out which page each process is loaded on. Via javascript though? In no case.

0
source

Extracted from Quora

Most sounds on the Internet are made through Flash. The flash does not tell the browser when it makes a sound. That is, if Flash works on two different tabs, the browser cannot know which one is making sound.

Implementing the HTML5 tag environment may help in this area, but I Wait while working for some time (for non-Flash pages) would be more unpleasant than there is no sound indicator.

(Ignore the comment below (in a related Quora question) saying that Chrome displays a β€œplay” icon when playing sound. Soundcloud changes the title of its page, not Google Chrome)

+1
source

I don’t think you can determine if the speakers create in JavaScript, but you may not have to.

Perhaps you can track this yourself, implicitly. For example, if there is a play button, when pressed, you can start playing the sound and show the icon. As soon as the user presses the stop button, you stop the sound and hide the icon.

0
source

It may help you, fbc_array to use the noise of the fbc_array[value] array to get this noise. example:

 window.onload = function() { var file = document.querySelector('input'); file.onchange = function(e) { var boton = e.target.files; var archivo = boton[0]; if (!archivo.type.match(/audio/)) { alert("Seleciona un audio, por favor."); } else { var lector = new FileReader(); lector.readAsDataURL(archivo); lector.addEventListener("load", initMp3Player, false); } } function initMp3Player(e) { var result = e.target.result; var audio = document.querySelector('audio'); audio.src = result; context = new AudioContext(); analyser = context.createAnalyser(); source = context.createMediaElementSource(audio); source.connect(analyser); analyser.connect(context.destination); frameLooper(); } function frameLooper() { window.requestAnimationFrame(frameLooper); fbc_array = new Uint8Array(analyser.frequencyBinCount); analyser.getByteFrequencyData(fbc_array); document.querySelector('#o1').style.transform = 'scale(' + fbc_array[1] / 75 + ')'; document.querySelector('#o2').style.transform = 'scale(' + fbc_array[50] / 100 + ')'; document.querySelector('#o3').style.transform = 'scale(' + fbc_array[100] / 200 + ')'; } } 
 * { margin: 0; padding: 0; cursor: default; } body { background: #222; } input { position: fixed; left: 0; right: 0; margin: auto; background: rgb(76, 142, 250); border: 0; border-radius: 2px; box-sizing: border-box; color: #fff; cursor: pointer; font-size: .875em; padding: 10px 24px; } #o1 { position: fixed; display: block; top: 0; bottom: 0; left: 0; right: 0; height: 100px; width: 100px; background: #333; margin: auto; border-radius: 50%; } #o2 { position: fixed; display: block; top: 0; bottom: 0; left: 0; right: 0; height: 100px; width: 100px; margin: auto; background: #0074d9; border-radius: 50%; } #o3 { position: fixed; display: block; top: 0; bottom: 0; left: 0; right: 0; height: 100px; width: 100px; margin: auto; background: #fff; border-radius: 50%; } 
 <input type="file"></input> <audio autoplay></audio> <div id="o1"></div> <div id="o2"></div> <div id="o3"></div> 
0
source

Source: https://habr.com/ru/post/1339698/


All Articles