Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda