Skip to main content
Electric_kindness5C3F
Participant
June 2, 2024
Question

How to add background music to HTML5 projects that play continuously?

  • June 2, 2024
  • 2 replies
  • 310 views

Hey everyone!

 

I'm working on an HTML5 project and I need to add background music that plays independently from the timeline. I've set the sync settings to stream, but the music stops when there is a frame stoppage in the animation. There are also moments where the user clicks a button and returns to earlier moments in the animation and the music plays from that point instead of continuously. I've searched the forums, youtube videos, and support guides but just can't find an answer that works for me. Appreciate any help!

This topic has been closed for replies.

2 replies

nurba
Participating Frequently
June 7, 2024

Hi,

what about playing music through the code?

 

// play music soundtrack on first touch of stage
stage.addEventListener("stagemousedown", playMusic);
 
function playMusic(evt) {
// remove the touch listener not to get triggered again
stage.removeEventListener("stagemousedown", playMusic);
// play music soundtrack
createjs.Sound.play("bgmusic", {
loop: -1
});
}
kglad
Community Expert
Community Expert
June 2, 2024

use event, not stream