Skip to content

Commit 6882858

Browse files
authored
Fix bug in handling processSound callback when sound hadn't loaded yet (#5414)
Co-authored-by: Noeri Huisman <mrxz@users.noreply.github.com>
1 parent 17f06f6 commit 6882858

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/components/sound.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ module.exports.Component = registerComponent('sound', {
9191

9292
// Remove this key from cache, otherwise we can't play it again
9393
THREE.Cache.remove(data.src);
94-
if (self.data.autoplay || self.mustPlay) { self.playSound(this.processSound); }
94+
if (self.data.autoplay || self.mustPlay) { self.playSound(self.processSound); }
9595
self.el.emit('sound-loaded', self.evtDetail, false);
9696
});
9797
}

tests/components/sound.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,23 @@ suite('sound', function () {
176176
assert.ok(sound.play.called);
177177
});
178178

179+
test('plays sound and calls processSound callback when not loaded', function (done) {
180+
var el = this.el;
181+
var processSoundStub = sinon.stub();
182+
183+
el.setAttribute('sound', 'src', 'url(base/tests/assets/test.ogg)');
184+
el.components.sound.playSound(processSoundStub);
185+
assert.notOk(el.components.sound.isPlaying);
186+
assert.ok(el.components.sound.mustPlay);
187+
188+
el.addEventListener('sound-loaded', function () {
189+
assert.ok(el.components.sound.isPlaying);
190+
assert.notOk(el.components.sound.mustPlay);
191+
assert.ok(processSoundStub.calledOnce);
192+
done();
193+
});
194+
});
195+
179196
test('plays sound if sound already playing when changing src', function (done) {
180197
var el = this.el;
181198
var playSoundStub = el.components.sound.playSound = sinon.stub();

0 commit comments

Comments
 (0)