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

136
Visualizações
event.target.setVolume(0); doesn't work by itself, why?
event.target.setVolume(0); // doesn't work by itself

In fact, in the next line

t.getVolume(); // spits 100, always

But when it is placed inside an event handler, it does. Why?

scroll.addEventListener('wheel', function (e) { changeVolume(e, this) });
    function changeVolume(event, el)
    {
        const dir = Math.sign(event.deltaY) * -1;
        const parsed = parseInt(el.value, 10);
        const value = Number(dir + parsed);
        t.setVolume(value); // TARGET
        // OH wait! Now - it does work. Why?
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Ok. So the iframe needs to be loaded to change -this-one-property-, everything else works fine - set - get - : PlaybackRate, sekto, unMute, mute... EVERYTHING!!

Within the target proto: store a closure with the desired volume and protect yourself with a guard clause.

function onPlayerReady(event)
{
    const t = event.target;

    function printVol()
    {
        console.log(
            {
                getVol: t.getVolume(), //nope
                volume: t.__proto__.newVol
            }
        );
    }
    function readyToChangeVolumeOnce()
    {
        if (!t.__proto__.changedVolumeOnce)
        {
            t.__proto__.changedVolumeOnce = true;
            t.setVolume(t.__proto__.newVol);
            printVol(); // works as expected... right. Should I be doing this?
        }
    }

    // javascript is crazy
    t.__proto__.changedVolumeOnce = false;
    t.__proto__.readyToChangeVolumeOnce = readyToChangeVolumeOnce;
    t.__proto__.newVol = validVolume(); // 20 for example
}

Once the iframe (API) knows it's alright to play, then call the function inside the proto.

function onStateChange(state)
{
    const t = state.target;
    if (state.data === YT.PlayerState.PLAYING)
    {
       t.__proto__.readyToChangeVolumeOnce(); //man...
    }
}

It's a workaround, I don't think it is an answer per se. I'm happy it works though. I also noticed that t.unmute() assigns a low volume if the volume was 0. Again, everybody, all of this could be a MAJOR misunderstanding form my end. I don't know.

about 4 years ago · Juan Pablo Isaza Relatório
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