Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!