IonDen / ion.sound

JavaScript plugin for playing sounds and music in browsers
http://ionden.com/a/plugins/ion.sound/en.html
MIT License
713 stars 154 forks source link

Loop keeps playing after stopped, if execution was suspended in debugger for a while #88

Open alexeyv opened 6 years ago

alexeyv commented 6 years ago

To reproduce the problem:

  1. Start a short sound with loop: true
  2. Put a breakpoint on sound.stop call (or anywhere else, really)
  3. Trigger the breakpoint
  4. Wait for a bit, then resume execution.

Expected: loop stops Actual: loop keeps merrily looping after the sound.stop() call. An hour-long dive through the app and the library to figure out what can possible be restarting the loop ensues. Actually, nothing does, it's only the interplay between this if and having JavaScript engine paused for a while when the loop was playing.

I'm not sure I completely understand the subtleties of (this.time_offset >= this.end || this.end - this.time_offset < 0.015) condition, so maybe this PR breaks some other case I'm not thinking of. But it surely solves the described problem. :)

Please have a close look.