better fix for #912 by stopping only the most recently created source on player.restart(); reverting prior fix attempt which didn't address all possible cases adequately

This commit is contained in:
Marcel Blum 2021-10-29 22:27:55 -04:00
parent 6700a3c5f5
commit 05a4ef7cf2
2 changed files with 3 additions and 4 deletions

View file

@ -168,8 +168,7 @@ export abstract class OneShotSource<
// schedule the stop callback
this._stopTime = this.toSeconds(time) + fadeOutTime;
const nowTime = this.now();
this._stopTime = Math.max(this._stopTime, nowTime);
this._stopTime = Math.max(this._stopTime, this.now());
if (fadeOutTime > 0) {
// start the fade out curve at the given time
if (this._curve === "linear") {
@ -189,7 +188,7 @@ export abstract class OneShotSource<
this._curve === "exponential" ? fadeOutTime * 2 : 0;
this._stopSource(this.now() + additionalTail);
this._onended();
}, this._stopTime - nowTime);
}, this._stopTime - this.context.currentTime);
return this;
}

View file

@ -261,7 +261,7 @@ export class Player extends Source<PlayerOptions> {
}
protected _restart(time?: Seconds, offset?: Time, duration?: Time): void {
this._stop(time);
[...this._activeSources].pop()?.stop(time); // explicitly stop only the most recently created source, to avoid edge case when > 1 source exists and _stop() erroneously sets all stop times past original end offset
this._start(time, offset, duration);
}