Looping sound on multiple frames?

I’m working on a game that has different frames for different levels. Ex. you complete level 1, it takes you to frame 2 of the project, which has level 2, and so forth. Well, I wanted the same background music to play throughout the game, preferably seamlessly looping. Initially, I didn’t realize that it’s not possible to use playSound for this. When looking at the wick engine code, it’s pretty clear that playSound is only meant to apply to a single frame at a time. It adds sound to a frame, and you can loop the sound so long as you stay on that frame. After realizing this, I’ve been trying to think of an alternative method to have the background music loop for multiple frames. Anyone got any ideas? I thought of a few, but they haven’t really worked out yet…for example, I tried to put the sound in a clip that would exist on multiple frames and just have the clip loop, but that didn’t work when I tried it.

Try making a new layer and making a frame in that layer that has the background music and making the frame span across all the other frames.

I tried doing that…for some reason it didn’t work for me. I guess I should specify that it didn’t seem to work when exporting to HTML - which is the format I eventually want to use when it’s complete. So if it loops successfully while running in the editor but not when exported, I can’t use that method. I’ll try it again just to be sure though.

Welp, I guess it works after all, sorry for the wasted time. I could’ve sworn last time I tried this, it wasn’t looping in the browser, but maybe I just put the code in the wrong script or something…thanks for persuading me to try it again, I’m glad it’s that simple.

You can also use hacks

project.bgMusic = this.project.getAssetByName("bg-music.mp3");

project.bgMusic.play({loop: true});
project.bgMusic.stop();
2 Likes

Unfortunately it started happening again…exported to HTML, tried running it in Google Chrome, the music track reached the end, and it didn’t loop. I think maybe it’s browser-specific, but I would like to try to find a solution. I’ll try researching how howler.js works since admittedly I’ve never really used it before now, I don’t know much about it.

1 Like

I have experienced the same, sometimes it loops and sometimes not.

2 Likes

i haven’t had this looping problem, maybe i just need to be weird with the keys and stuff.

enjoy waiting for 2000 years

keypressed 2000yearslater thingy10-19-2020_6-38-46PM.wick (55.7 KB)

I think the looping sounds work when they’re activated by something (like the user pressing a key), but what I had in mind was some background music that plays from the beginning of the game and all throughout it, without the user having to do anything to start the sound playing. And for some reason, the sound loop didn’t work for me then (not when exporting to HTML, at least)

I’m making some test
apparently

project.bgMusic = this.project.getAssetByName("wickLove.wav");
project.bgMusic.play({loop: true});

do not loops the background music on a single non stopped frame
do loops on a single stopped frame
do loops on multiple running frames

The project.bgMusic.play({loop: true}); Didn’t work for me

Are you sure?
check this wick.
it works for me but as you can see it is the 3° case (multiple running frames)
also note that the attached files uses a .mp3 file instead of .wav. both do work
audioLoop.wick (214.9 KB)

well actually it works only in the editor
when exported in html wont work :zipper_mouth_face:

I dont know if this should be reported as a bug as it is not a strict wickeditor command/function
for sure I’d like to have a reliable way of looping audio

I don’t know if this will help anyone else, but I was also having trouble looping audio. I realized I had to use a mouseclick at the very beginning of my timeline, instead of a mousepress. I think Chrome in particular requires a mouseclick (that’s both a down and an up), before starting audio that will loop. Try a mouseclick before starting audio that loops, and you may get reliable results. And also, be sure not to start the audio in the button click. Start the audio on the second frame. Using a mouseclick and starting the audio on the next frame worked for me.

3 Likes

Thank you for sharing it:

You are right. For games, usually I put a “start game” button, so the user is forced to do the mouse click (pressing the button). Then, after that, I start the music. For loops, at least if you host the game using the html zip file, the sound loop works fine. For games I use the following code…

playSound("mySound.mp3",{loop:true});