First Time SoundJS User, Can't Seem To Get A Sound To Play

943 Views Asked by At

I'm just... trying to get SoundJS to play a sound. It appears that the file never load as my handleLoad function is never called. Any ideas?

    var audioPath = "snd/";
    var sounds = [
        { id: "mySound", src: "gaia.mp3" }
    ];

    function init( ) {
        createjs.Sound.addEventListener( "fileload", handleLoad );
        createjs.Sound.registerSounds( sounds, audioPath );
    }

    function handleLoad( event ) {
        console.log( "Hello from handleLoad" );
    }

I get a "creates.Sound.registerSounds is not a function" error when init runs.

1

There are 1 best solutions below

0
On

Your demo should work.

I copied your code into a JSFiddle, and pointed it at a sound that I know exists.https://jsfiddle.net/lannymcnie/vj8rLghb/

The only difference is I added the 3rd parameter because it is being loaded cross-domain

createjs.Sound.addEventListener("fileload", handleLoad, true);

Additionally, changes in Chrome mean that audio can't play without a user interaction, so once the audio is loaded, I added a document-click listener so it plays when you click the page anywhere.

Can you post the full error you get in the console? It is unclear if registerSounds is undefined, or if it doesn't exists on undefined, which indicates that createjs.Sound is undefined. Have you ensured that SoundJS is included properly? Try putting this in the console:

console.log(createjs.Sound);

Hope that helps!