play() function doesn't work
Hello everyone,
I recently encountered an issue while trying to play audio in OSWeb Version >=2. I was attempting to use the `play()` method on an audio object, but I kept getting the error "play() is not a function". With OSWeb Version <=2 it works fine!
audio = runner._pool[audioname].data audio.play()
I also tried, with the same error "TypeError: pool[audioname].play is not a function":
pool[audioname].play();
After some troubleshooting, I found a solution that works using direct access to the AudioBuffer. Here's the code that solved the problem:
var audioContext = new (window.AudioContext || window.webkitAudioContext)(); var source = audioContext.createBufferSource(); source.buffer = pool[audioname].data; source.connect(audioContext.destination); source.start(0);
Does anyone else have the same problem with the new OSWeb version >=2? How did you solve it?
Regrads, Max
Comments
Hi @stef_max ,
Thanks for pointing this out. That's correct, and it results from sound playback now being handled by the Web Audio API, which is more modern and better supported on various browser than the previous implementation. But indeed, the example from the docs now longer works, and you need to work around it more or less as you have. I'll update the docs!
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!