event.target.setVolume(0); // doesn't work by itselfDe hecho, en la siguiente línea
t.getVolume(); // spits 100, alwaysPero cuando se coloca dentro de un controlador de eventos, lo hace. ¿Por qué?
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? }Está bien. Entonces, el iframe debe cargarse para cambiar -this-one-property-, todo lo demás funciona bien - establecer - obtener -: PlaybackRate, sekto, unMute, mute... ¡TODO!
Dentro del proto target: guarda un cierre con el volumen deseado y protégete con una cláusula de guarda.
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 }Una vez que el iframe (API) sepa que está bien jugar, llame a la función dentro del proto .
function onStateChange(state) { const t = state.target; if (state.data === YT.PlayerState.PLAYING) { t.__proto__.readyToChangeVolumeOnce(); //man... } } Es una solución alternativa, no creo que sea una respuesta per se. Aunque estoy feliz de que funcione. También noté que t.unmute() asigna un volumen bajo si el volumen era 0 . Nuevamente, todos, todo esto podría ser un GRAN malentendido de mi parte. No sé.