im currently working on a chrome extension that need to detect if an audio is playing in the browser. I've found this post with a lot of solutions : Detect if audio is playing in browser Javascript
Complete JSFiddle : https://jsfiddle.net/Thornton_Fernbacher/mg3uv54j/73/
startBtn.onclick = function() {
startBtn.onclick = null;
navigator.mediaDevices.getDisplayMedia({
video: true,
audio: true
})
.then(stream => {
if (stream.getAudioTracks().length > 0) {
var source = audioCtx.createMediaStreamSource(stream);
source.connect(analyser);
document.body.classList.add('ready');
} else {
console.log('Failed to get audiostream. Audio not shared or browser not supported')
}
}).catch(err => console.log("Unable to open capture: ", err));
audioCtx.resume();
}
function checkAudio() {
check.classList.toggle('playing', window.isAudioPlaying());
window.requestAnimationFrame(checkAudio);
}
checkAudio();
I tried first a JSFiddle who was working kind of perfectly. But, once i've tried to integer inside my extension, it doest work as expected. First, the start button doesnt open any alert to ask authorization and so the next code is impossible to execute. So i searched for the permissions of Chrome extension but i found nothing that cancel alerts.
So im looking to someone who knows a solution for this chrome extension that can help me. Have a good day.