Skip to content

Commit a6b4066

Browse files
Moved logic for setting up and playing audio tag so it can be reused
1 parent f9093a2 commit a6b4066

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/sound/html5/HTML5AudioSound.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,9 @@ var HTML5AudioSound = new Class({
4444
if (!BaseSound.prototype.play.call(this, markerName, config)) {
4545
return false;
4646
}
47-
if (!this.pickAudioTag()) {
48-
this.reset();
47+
if (!this.pickAndPlayAudioTag()) {
4948
return false;
5049
}
51-
var seek = this.currentConfig.seek;
52-
var delay = this.currentConfig.delay;
53-
var offset = (this.currentMarker ? this.currentMarker.start : 0) + seek;
54-
this.audio.currentTime = offset;
55-
this.applyConfig();
56-
if (delay === 0) {
57-
this.startTime = 0;
58-
this.audio.play();
59-
}
60-
else {
61-
this.startTime = window.performance.now() + delay;
62-
}
63-
this.resetConfig();
6450
this.events.dispatch(new SoundEvent(this, 'SOUND_PLAY'));
6551
return true;
6652
},
@@ -96,6 +82,26 @@ var HTML5AudioSound = new Class({
9682
this.events.dispatch(new SoundEvent(this, 'SOUND_STOP'));
9783
return true;
9884
},
85+
pickAndPlayAudioTag: function () {
86+
if (!this.pickAudioTag()) {
87+
this.reset();
88+
return false;
89+
}
90+
var seek = this.currentConfig.seek;
91+
var delay = this.currentConfig.delay;
92+
var offset = (this.currentMarker ? this.currentMarker.start : 0) + seek;
93+
this.audio.currentTime = offset;
94+
this.applyConfig();
95+
if (delay === 0) {
96+
this.startTime = 0;
97+
this.audio.play();
98+
}
99+
else {
100+
this.startTime = window.performance.now() + delay;
101+
}
102+
this.resetConfig();
103+
return true;
104+
},
99105
pickAudioTag: function () {
100106
if (!this.audio) {
101107
for (var i = 0; i < this.tags.length; i++) {

0 commit comments

Comments
 (0)