#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)

runic crane
#

pretty basic. give it a try yourself and ask questions.

buoyant oriole
#
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
runic crane
#

See #faq for curated resources to learn.

#

Does it work?

buoyant oriole
#

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>    ```
runic crane
#

build something with their docs. get it working. then convert it to your app

buoyant oriole
#

In the end I preferred not to use that complicated player and opted to use simple html5 audio

#

I found an example for exactly what I wanted I'll leave it here in case someone finds it useful