Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

224
Visualizações
Why audio is not working after using Audio Context?

I developed a Firefox addon to increase the output of the speaker. I used AudioContext for this.

On YouTube videos it is working fine but on other websites it is not working. So I figured out that this was because of DOM is not loaded. So I now if I am waiting for DOM to load completely, there is no sound coming out of the speakers even for YouTube which was working previously.

Here is the code, I tried putting it inside DOMReady and other methods that waits for DOM to load but Audio stops working after this.

let mVideoElement = document.querySelector('video');
let audioCtx = new AudioContext();
let source = audioCtx.createMediaElementSource(mVideoElement);
let gainNode = audioCtx.createGain();

browser.storage.onChanged.addListener((changes, area) => {
    if (area === 'local' && 'value' in changes) {
        increaseVolume(changes.value.newValue);
    }

    if (area === 'local' && 'status' in changes) {
        speakerBoosterStatus(changes.status.newValue);
    }
});

function increaseVolume(value) {
    if (value === undefined) {
        gainNode.gain.value = 1;
    } else {
        gainNode.gain.value = value;
    }
    source.connect(gainNode);
    gainNode.connect(audioCtx.destination);
}


function speakerBoosterStatus(status) {
    if (status === false) {
        gainNode.gain.value = 1;
        source.connect(gainNode);
        gainNode.connect(audioCtx.destination);
        window.location.reload();
    } else {
        browser.storage.local.get('value').then(result => increaseVolume(result.value));
    }
}

browser.storage.local.get('value').then(result => increaseVolume(result.value));
browser.storage.local.get('status').then(result => speakerBoosterStatus(result.value));

Here is the Source Code for better testing.

PR are welcome. Thank you :)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda