mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
additional safety flag for if the internal BufferSourceNode is actually started
checking if the offset < duration keeps safari from going into invalid state
This commit is contained in:
parent
3f996c2bc0
commit
5ba49351d9
1 changed files with 16 additions and 2 deletions
|
@ -27,6 +27,15 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source", "Tone/core/G
|
|||
*/
|
||||
this._startTime = -1;
|
||||
|
||||
/**
|
||||
* An additional flag if the actual BufferSourceNode
|
||||
* has been started. b/c stopping an unstarted buffer
|
||||
* will throw it into an invalid state
|
||||
* @type {Boolean}
|
||||
* @private
|
||||
*/
|
||||
this._sourceStarted = false;
|
||||
|
||||
/**
|
||||
* The time that the buffer is scheduled to stop.
|
||||
* @type {Number}
|
||||
|
@ -211,7 +220,10 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source", "Tone/core/G
|
|||
this._source.buffer = this.buffer.get();
|
||||
this._source.loopEnd = this.loopEnd || this.buffer.duration;
|
||||
Tone.isPast(time);
|
||||
if (offset < this.buffer.duration){
|
||||
this._sourceStarted = true;
|
||||
this._source.start(time, offset);
|
||||
}
|
||||
} else {
|
||||
throw new Error("Tone.BufferSource: buffer is either not set or not loaded.");
|
||||
}
|
||||
|
@ -285,7 +297,9 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source", "Tone/core/G
|
|||
Tone.BufferSource.prototype._onended = function(){
|
||||
//allow additional time for the exponential curve to fully decay
|
||||
var additionalTail = this.curve === "exponential" ? this.fadeOut * 2 : 0;
|
||||
if (this._sourceStarted){
|
||||
this._source.stop(this._stopTime + additionalTail);
|
||||
}
|
||||
this.onended(this);
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue