phaser icon indicating copy to clipboard operation
phaser copied to clipboard

sound.play() doesn't play simultaneous sounds

Open steveja42 opened this issue 2 years ago • 5 comments

When I call .play() for a sound more than once, the previous plays are stopped when the new one starts so they don't play simultaneously. Sounds played using using audiosprites do play simultaneously. I'm using webaudio:

    public preload() {
            log(preload)
            this.load.audio("falling", ["assets/audio/mixkit-short-whistle-fall-406.mp3", "assets/audio/mixkit-short-whistle-fall-406.ogg"])

        }

    public create() {
        this.fallingSound = this.sound.add("falling", { loop: false }) ... 

then in update() or on a collision I am calling this.fallingSound.play()

steveja42 avatar Jan 25 '22 18:01 steveja42

A sound object has only one playback position.

You need to create a second sound object or use this.sound.play('falling') instead.

samme avatar Jan 26 '22 16:01 samme

Thank you very much for the information. I wish it were reflected in the documentation.

steveja42 avatar Jan 27 '22 17:01 steveja42

@steveja42 It is actually!

https://photonstorm.github.io/phaser3-docs/Phaser.Sound.HTML5AudioSoundManager.html

To play multiple instances of the same HTML5 Audio sound, you need to provide an instances value when loading the sound with the Loader

Mesonyx avatar Jan 28 '22 16:01 Mesonyx

That doesn't explain the difference between this.sound.play(key) and asoundInstance.play() that you pointed out. Also when I used instances in the loader asoundInstance.play() still started over every time so I don't see that instances did anything.

steveja42 avatar Jan 28 '22 18:01 steveja42

@steveja42 Fair enough

I believe you still need to use this.sound.play(key) otherwise calling play() on the instance directly will just restart that instance, as you mentioned

Mesonyx avatar Jan 28 '22 19:01 Mesonyx

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

photonstorm avatar Nov 18 '22 22:11 photonstorm