Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple seeks fail after some time #1158

Open
dirkk0 opened this issue Jan 13, 2023 · 1 comment
Open

Multiple seeks fail after some time #1158

dirkk0 opened this issue Jan 13, 2023 · 1 comment

Comments

@dirkk0
Copy link

dirkk0 commented Jan 13, 2023

Describe the bug

Multiple seeks fail after some time in the Player.

To Reproduce
codepen.
After the 4th time the seek fails, and the file plays to the end.

Expected behavior
seek should always work

Additional context
I slice the audio buffer to make the file shorter, the audio file was the only one that I could find that was long enough without CORS issues.
The slicing is not the problem, though, the same behaviour happens with the slice, it just takes longer to who up.

@jamieforth
Copy link

This seems to relate to the implicit stop event not being updated within seek(), i.e. the player's state becomes stopped at startTime + duration regardless of the current playback position.

A workaround is to cancel the stopEvent before calling seek().

if (player._state.getValueAtTime(Tone.now()) === "started") {
    // Cancel the stop event since it's at a different time now.
    const stopEvent = player._state.getNextState("stopped", Tone.now());
    if (stopEvent && stopEvent.implicitEnd) {
            player._state.cancel(stopEvent.time);
            player.seek(offset, Tone.now());
    }
}

Or just to use player.restart(Tone.now(), offset) instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants