#Can someone help me to change the functions of this script to those of the PIXI Sound API?
10 messages · Page 1 of 1 (latest)
const icon = document.querySelector("#button > i");
const sound = PIXI.sound.Sound.from('sound');
button.addEventListener("click", () => {
if (sound.paused) {
sound.play();
icon.classList.remove('fa-volume-up');
icon.classList.add('fa-volume-mute');
} else {
sound.paused();
icon.classList.remove('fa-volume-mute');
icon.classList.add('fa-volume-up');
}
button.classList.add("fade");
});```
I tried it like this, honestly I don't know what I'm doing. I promise to do a javascript course xD
really, excuse my ignorance
It doesn't work, this API is complicated for me, I was looking for a while and I think I should save the object in a global variable
<script>
PIXI.sound.Sound.from({
url: 'mp3/audio.mp3',
loop:true,
preload: true,
loaded: function(err, sound) {
sound.play();
document.querySelector("#paused").addEventListener('click', function() {
const paused = PIXI.sound.togglePauseAll();
this.className = this.className.replace(/\b(on|off)/g, '');
this.className += paused ? 'on' : 'off';
});
}
});
</script> ```
build something with their docs. get it working. then convert it to your app
their docs are decent, with this demo: https://pixijs.io/sound/examples/demo.html