Use setTargetAtTime

This commit is contained in:
VisualSJ
2018-01-23 15:00:51 +08:00
parent 8c0a7a013c
commit 781efe4ab6
+21 -6
View File
@@ -282,9 +282,17 @@ var WebAudioElement = function (buffer, audio) {
this._audio = audio;
this._context = sys.__audioSupport.context;
this._buffer = buffer;
this._volume = this._context['createGain']();
this._volume['gain'].value = 1;
this._volume['connect'](this._context['destination']);
this._gainObj = this._context['createGain']();
this._volume = 1;
// https://www.chromestatus.com/features/5287995770929152
if (this._gainObj['gain'].setTargetAtTime) {
this._gainObj['gain'].setTargetAtTime(this._volume, this._context.currentTime, 0.01);
} else {
this._gainObj['gain'].value = 1;
}
this._gainObj['connect'](this._context['destination']);
this._loop = false;
// The time stamp on the audio time axis when the recording begins to play.
this._startTime = -1;
@@ -313,7 +321,7 @@ var WebAudioElement = function (buffer, audio) {
var audio = this._context["createBufferSource"]();
audio.buffer = this._buffer;
audio["connect"](this._volume);
audio["connect"](this._gainObj);
audio.loop = this._loop;
this._startTime = this._context.currentTime;
@@ -398,9 +406,16 @@ var WebAudioElement = function (buffer, audio) {
return this._loop = bool;
});
proto.__defineGetter__('volume', function () { return this._volume['gain'].value; });
proto.__defineGetter__('volume', function () {
return this._volume;
});
proto.__defineSetter__('volume', function (num) {
this._volume['gain'].value = num;
this._volume = num;
if (this._gainObj['gain'].setTargetAtTime) {
this._gainObj['gain'].setTargetAtTime(this._volume, this._context.currentTime, 0.01);
} else {
this._volume['gain'].value = num;
}
if (sys.os === sys.OS_IOS && !this.paused && this._currentSource) {
// IOS must be stop webAudio
this._currentSource.onended = null;