I hear the bongo play once just fine. But then, I’m using Chrome which can play OGG files. You might be using a browser that can’t. MP3 is a much better format for playing in just about any browser.
You are right… apparently FIREFOX have issues playing OGG files… I managed to play the sound on the mobile browser… Thanks playcanvas… Will try mp3 to make sure it works on all platforms
I have been trying to make a script that plays a sound when space key is pressed but it wont work I need help
this is what i have:
annonMove.prototype.update = function(dt) {
if( this.app.keyboard.isPressed(pc.input.KEY_RIGHT)){
this.entity.translateLocal(0, 0, -0.3);
}
if( this.app.keyboard.isPressed(pc.input.KEY_LEFT)){
this.entity.translateLocal(0, 0, 0.3);
}
if ( this.app.keyboard.isPressed(pc.KEY_SPACE)){
this.entity.sound.play(‘Sound’);
You need to remove the boolean. As it is, every frame the game checks to see if the button is pressed, and because of how frequently that is your boolean playing gets set true, and then false instantly, so no sound. if(app.keyboard.isPressed(pc.KEY_SPACE)) is enough on it’s own to trigger the sound event. If you have a problem with the sound continuing to play after the key has been released, just turn off loop.
EDIT: I stand corrected, I’m not getting sound when I test this.
On Chrome there’s a google policy change and a warning in console that says “The AudioContext was not allowed to start. It must be resume (or created) after a user gesture on the page. https://goo.gl/7K7WLu”
What this means is that Google Chrome has done something that I think is fairly silly. My understanding is that they’ve broken the audio for every HTML5 game until the developers of said game add extra code to re-enable the audio based on a user gesture event.
While this is the case, I’ve simply moved to using and recommending Firefox to all users of my game
Maybe the PlayCanvas devs can implement a workaround for Chrome’s arbitrary restrictions in the engine itself, but until then we have to handle it ourselves.