kittykatattack / sound.js

A micro-library to load, play and generate sound effects and music for games and interactive applications
300 stars 44 forks source link

Pause/Resume while maintaining an accurate song time? #19

Open CloverFeywilde opened 6 years ago

CloverFeywilde commented 6 years ago

Trying to use this for implementation in my rhythm game, but the way this is written makes it very difficult to implement a pause feature for my game.

Everything in my game depends on me knowing at all times an accurate number for the song's current playback time. In a resolved issue someone pointed out that I could use:

sounds['src'].soundNode.context.currentTime - sounds['src'].startTime

This works like a charm.... until the song gets paused. As soon as the song is resumed, sounds['src'].startTime jumps up to equal sounds['src'].soundNode.context.currentTime and the whole thing just becomes a mess to keep track of.

Can anyone help me come up with a way that I can pause the song, and when it's resumed, still maintain an accurate song play time?