mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 13:43:26 +00:00
moved source buffer creation and starting to separate method for reuse
This commit is contained in:
parent
e6f17744b6
commit
478656df98
1 changed files with 19 additions and 10 deletions
|
@ -61,11 +61,8 @@ var WebAudioSound = new Class({
|
|||
if (this.source) {
|
||||
this.source.stop();
|
||||
}
|
||||
this.source = this.manager.context.createBufferSource();
|
||||
this.source.buffer = this.audioBuffer;
|
||||
this.source.connect(this.muteNode);
|
||||
this.applyConfig();
|
||||
this.source.start(0, 0, this.currentConfig.duration);
|
||||
// TODO include config offset and marker start
|
||||
this.createAndStartBufferSource(0, this.currentConfig.duration);
|
||||
this.startTime = this.manager.context.currentTime;
|
||||
this.pausedTime = 0;
|
||||
return this;
|
||||
|
@ -79,11 +76,9 @@ var WebAudioSound = new Class({
|
|||
},
|
||||
resume: function () {
|
||||
BaseSound.prototype.resume.call(this);
|
||||
this.source = this.manager.context.createBufferSource();
|
||||
this.source.buffer = this.audioBuffer;
|
||||
this.source.connect(this.muteNode);
|
||||
this.applyConfig();
|
||||
this.source.start(0, this.pausedTime, this.currentConfig.duration - this.pausedTime);
|
||||
var offset = this.pausedTime; // TODO include marker start time
|
||||
var duration = this.currentConfig.duration - this.pausedTime;
|
||||
this.createAndStartBufferSource(offset, duration);
|
||||
this.startTime = this.manager.context.currentTime - this.pausedTime;
|
||||
this.pausedTime = 0;
|
||||
return this;
|
||||
|
@ -96,6 +91,20 @@ var WebAudioSound = new Class({
|
|||
this.pausedTime = 0;
|
||||
return this;
|
||||
},
|
||||
/**
|
||||
* Used internally to do what the name says.
|
||||
*
|
||||
* @private
|
||||
* @param {number} offset
|
||||
* @param {number} duration
|
||||
*/
|
||||
createAndStartBufferSource: function (offset, duration) {
|
||||
this.source = this.manager.context.createBufferSource();
|
||||
this.source.buffer = this.audioBuffer;
|
||||
this.source.connect(this.muteNode);
|
||||
this.applyConfig();
|
||||
this.source.start(0, offset, duration);
|
||||
},
|
||||
update: function () {
|
||||
},
|
||||
destroy: function () {
|
||||
|
|
Loading…
Reference in a new issue