LingDong- / q5xjs

A small and fast alternative (experimental) implementation of p5.js
https://q5xjs.netlify.app/
The Unlicense
547 stars 25 forks source link

q5 + p5 sound #17

Open werls opened 2 years ago

werls commented 2 years ago

The q5 has been a very important tool in my processes. While p5 was a first step, q5 seems to lead me towards a better understanding of the processes and the possibility of being less and less dependent on a specific library. Thank you!

I'm trying to use the q5 together with the p5 sound and I followed everything that was indicated in the README: I included and linked the q5.p5acl.js in the correct sequence:

<script src="https://cdn.jsdelivr.net/gh/LingDong-/q5xjs/q5.min.js"></script>
<script src="./q5.p5acl.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/addons/p5.sound.min.js"></script>

I was able to load the audio file using let mySound = addons.loadSound('soundfile.mp3'), but I can't use the same principle as p5 to play the sound: mySound.play().

This is my entire code:

let q5 = new Q5()
let mySound = addons.loadSound("Damscray_DancingTiger.mp3");

q5.setup = () => {
  q5.createCanvas(100, 100)
  q5.background(0)
}

q5.canvas.addEventListener('click', () => {
  console.log('click')
  mySound.play()
})

And this is the error on the console: InvalidStateError: Failed to construct 'AudioWorkletNode': AudioWorkletNode cannot be created: AudioWorklet does not have a valid AudioWorkletGlobalScope. Load a script via audioWorklet.addModule() first. at undefined:2:97382

Am I making a mistake or is some additional code needed?

quinton-ashley commented 1 year ago

I added basic loadSound functionality to my upgrade to q5js that you can use without even loading p5.sound.js

https://github.com/quinton-ashley/q5js

quinton-ashley commented 10 months ago

p5.sound is now fully compatible with my fork of q5