Offset on sounds api

This commit is contained in:
2026-11-22 08:35:54 -03:00
parent d18fe19027
commit 5d374091cd
5 changed files with 58 additions and 4 deletions
+6 -1
View File
@@ -134,6 +134,11 @@ class WebVoice implements Voice {
this.ended = true;
return;
}
// played with an offset past its end, it would have finished already
if (!settings.loop && settings.offset >= buffer.duration) {
this.stop();
return;
}
const source = new AudioBufferSourceNode(context, {
buffer,
loop: settings.loop,
@@ -144,7 +149,7 @@ class WebVoice implements Voice {
this.ended = true;
this.#disconnect();
};
source.start(0, settings.loop ? settings.offset % buffer.duration : 0);
source.start(0, settings.offset % buffer.duration);
this.#source = source;
});
}