Skip to content

Commit dfff190

Browse files
committed
[FIX] Fix resuming sounds from the same spot after pausing
1 parent 057d40c commit dfff190

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/sound/instance.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ pc.extend(pc, function () {
198198
if (this._state !== STATE_PLAYING || !this.source)
199199
return false;
200200

201+
// store current time
202+
this._updateCurrentTime();
203+
201204
// set state to paused
202205
this._state = STATE_PAUSED;
203206

@@ -438,6 +441,16 @@ pc.extend(pc, function () {
438441
return this.source;
439442
},
440443

444+
/**
445+
* @private
446+
* @function
447+
* @name pc.SoundInstance#_updateCurrentTime
448+
* @description Sets the current time taking into account the time the instance started playing, the current pitch and the current time offset.
449+
*/
450+
_updateCurrentTime: function () {
451+
this._currentTime = capTime((this._manager.context.currentTime - this._startedAt) * this.pitch + this._currentOffset, this.duration);
452+
},
453+
441454
/**
442455
* @private
443456
* @function
@@ -538,7 +551,7 @@ pc.extend(pc, function () {
538551
}
539552

540553
// recalculate current time
541-
this._currentTime = capTime((this._manager.context.currentTime - this._startedAt) * this.pitch + this._currentOffset, this.duration);
554+
this._updateCurrentTime();
542555
return this._currentTime;
543556
},
544557
set: function (value) {

0 commit comments

Comments
 (0)