Skip to main content
Participant
November 29, 2018
Answered

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

  • November 29, 2018
  • 2 replies
  • 1839 views

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 has been closed for replies.
Correct answer SynthesisMod

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?

2 replies

avid_body16B8
Legend
November 29, 2018

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.

Participant
November 29, 2018

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

Linkage is set, I'm still getting nothing.

Preran
Community Manager
Community Manager
December 3, 2018

Does this happen with all your files?

avid_body16B8
Legend
November 29, 2018

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)