Skip to main content
Participant
Nov 29, 2018 4:29 PM UTC
Answered

How do I play a sound using SoundJS in HTML Canvas?

I've tried a million things and can't get this sound to play either from the "test" menu item or from a local server.

I have previewed the sound in Animate and it plays, it's a 128kb MP3, and I've tried on Mac Safari, Chrome, and Firefox. Still, I get no sound.

I'm sure it's something simple... first time trying to do this... help is much appreciated!

My Code:

createjs.Sound.on("fileload", handleLoad); 

createjs.Sound.registerSound("sounds/discoSong.mp3", "myID", 3);

function handleLoad(event) {

  createjs.Sound.play("myID"); 

  var myInstance = createjs.Sound.play("myID");

  console.log(myInstance);

}

The output from that console.log:

a {_listeners: null, _captureListeners: null, src: "sounds/discoSong.mp3", uniqueId: 1, playState: "playSucceeded", …}

"playSucceeded"... I think not!

Thanks!

This topic is closed to new replies. Start a new post to keep the conversation going.
SynthesisModCorrect answer
Participant
Dec 5, 2018 3:40 PM UTC

Does this happen with all your files?


Problem solved, new computer, browser was blocking autoplay. Thanks for the help! How do I mark this discussion as closed?

14 replies

avid_body16B8
Legend
Nov 29, 2018 9:23 PM UTC

Explanation

this.incorrect = createjs.Sound.play("incorrect", "none", 0, 0, 0, 0.6);

this.incorrect = createjs.Sound.play("linkagename", "interrupt", delay, offset, loop, volume);

Of course you may be importing the sound to the stage which is a different story.

Translate
Participant
Nov 29, 2018 10:41 PM UTC

this.discoSong = createjs.Sound.play("discoSong", "none", 0, 0, 0, 0.6 );

Linkage is set, I'm still getting nothing.

Translate
Preran
Legend
Dec 3, 2018 6:28 PM UTC

Does this happen with all your files?

Translate
avid_body16B8
Legend
Nov 29, 2018 8:49 PM UTC

For example:

  • You need to add a linkage name for your sound file in the library.
  • this.incorrect = createjs.Sound.play("incorrect", "none", 0, 0, 0, 0.6);

incorrect: this is the linkage name

  • this.incorrect.paused = true;   (it stops)
  • this.incorrect.paused = false;   (it plays)
Translate