kaplayjs / kaplay

🦖 A JavaScript/TypeScript Game Library that feels like a game, fun
https://kaplayjs.com
MIT License
566 stars 37 forks source link

bug: setting loop: true when playing music doesn't set loop #527

Open cobrajs opened 2 days ago

cobrajs commented 2 days ago

Setting loop: true doesn't set loop for music

When playing music with play('music', { loop: true }), the loop property is not set.

Version

What version are you running?

To Reproduce

Steps to reproduce the behavior:

  1. Load music with loadMusic('music', '<url>')
  2. Play music with play('music', { loop: true })
  3. Wait for the music to finish playing the first time through. It should loop, or play again from the start, but it does not.

Expected behavior

Music should actually loop when loop: true is passed in for the AudioPlayOpt.

amyspark-ng commented 2 days ago

does this also happen when is loaded using loadSound rather than loadMusic

cobrajs commented 2 days ago

Using this example, it does loop correctly when using loadSound. Although doing that in that example, it looks like time() is reporting incorrectly when you speed up the music (as in, it loops correctly, but the time and progress bar are going to slow based on the set speed). I tested it out by increasing the speed to 5 because the example song is too long and I'm impatient haha

I got it to work locally by adding el.loop = Boolean(opt.loop); below this line, since playMusic() doesn't use the AudioPlayOpt the same way that play() does.