Multiple Instances of the Same Audio File

Demonstrates how to create and manage multiple independent sound instances using a single loaded audio asset.

Multiple Instances of the Same Audio File, running
800 × 600
GitHub
class Example extends Phaser.Scene
{
    preload ()
    {
        this.load.setBaseURL('https://cdn.phaserfiles.com/v410');
        this.load.audio('synth1', [
            'assets/audio/tech/synth1.ogg',
            'assets/audio/tech/synth1.mp3'
        ]);
    }

    create ()
    {
        const sound1 = this.sound.add('synth1', { loop: true });
        const sound2 = this.sound.add('synth1', { loop: true });

        sound1.play();
    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.AUTO,
    parent: 'game-container',
    width: 800,
    height: 600,
    scene: Example
};

const game = new Phaser.Game(config);

More in Web Audio16 examples