Reputation: 2600
WebAudio allows to access a microphone via navigator.getUserMedia()
. When calling this, Browsers show a recoding sign (red dot in Chrome and Edge) that indicates that the microphone is in use. This works fine, but I would like to be able to deactivate the microphone and then this red dot should also disappear. I thougth calling webcontext.close()
would also deactivate that red dot sign, but it doesnt, at least in Chrome, Firefox and Edge.
How do I deactivate a microphone in a way that also browsers recording signs disappear?
Upvotes: 8
Views: 2511
Reputation: 2600
I was able to find the solution myself, in case someone is interested:
Imagine we activate our microphone like this:
navigator.mediaDevices.getUserMedia(constraints).then(stream => {
this._userMediaInputStream = stream;
...
}).catch(errorFunction);
Then we can deactivate the microphone using the following piece of code. This will make the browser's recording symbol dissappear too:
this._userMediaInputStream.getAudioTracks().forEach(track => {
track.stop();
});
Upvotes: 14