From bf3e1960f8dd076000be1e6863bfd5a0185b4710 Mon Sep 17 00:00:00 2001 From: JonathannJacobs <102025137+JonathannJacobs@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:10:37 +0200 Subject: [PATCH 1/4] #5364 Bugfix : The processSound callback given to playSound() before the sound was loaded will be called when loaded and not ignored anymore. --- src/components/sound.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/sound.js b/src/components/sound.js index 920b30e1528..90f763e7b70 100644 --- a/src/components/sound.js +++ b/src/components/sound.js @@ -32,6 +32,7 @@ module.exports.Component = registerComponent('sound', { this.pool = new THREE.Group(); this.loaded = false; this.mustPlay = false; + this.processSound = undefined; // Saved callback for the mustPlay mechanic // Don't pass evt because playSound takes a function as parameter. this.playSoundBound = function () { self.playSound(); }; @@ -80,7 +81,7 @@ module.exports.Component = registerComponent('sound', { // Remove this key from cache, otherwise we can't play it again THREE.Cache.remove(data.src); - if (self.data.autoplay || self.mustPlay) { self.playSound(); } + if (self.data.autoplay || self.mustPlay) { self.playSound(this.processSound); } self.el.emit('sound-loaded', self.evtDetail, false); }); } @@ -208,6 +209,9 @@ module.exports.Component = registerComponent('sound', { if (!this.loaded) { warn('Sound not loaded yet. It will be played once it finished loading'); this.mustPlay = true; + if(processSound){ + this.processSound = processSound; + } return; } @@ -231,6 +235,7 @@ module.exports.Component = registerComponent('sound', { } this.mustPlay = false; + this.processSound = undefined; }, /** From f91140adf2eab85a9123bf55d18cd9bee780790d Mon Sep 17 00:00:00 2001 From: JonathannJacobs <102025137+JonathannJacobs@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:41:26 +0200 Subject: [PATCH 2/4] #5364 : Sound : Added API for reaching THREE.Audio.loopStart() and loopEnd() --- src/components/sound.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/sound.js b/src/components/sound.js index 90f763e7b70..42bcda54c6d 100644 --- a/src/components/sound.js +++ b/src/components/sound.js @@ -12,6 +12,8 @@ module.exports.Component = registerComponent('sound', { autoplay: {default: false}, distanceModel: {default: 'inverse', oneOf: ['linear', 'inverse', 'exponential']}, loop: {default: false}, + loopStart: {default: 0}, + loopEnd: {default: 0}, maxDistance: {default: 10000}, on: {default: ''}, poolSize: {default: 1}, @@ -59,6 +61,8 @@ module.exports.Component = registerComponent('sound', { sound.setRolloffFactor(data.rolloffFactor); } sound.setLoop(data.loop); + sound.setLoopStart(data.loopStart); + sound.setLoopEnd(data.loopEnd); sound.setVolume(data.volume); sound.isPaused = false; } From 61a5455342e32f436d44aee8e514ea791b77460e Mon Sep 17 00:00:00 2001 From: JonathannJacobs <102025137+JonathannJacobs@users.noreply.github.com> Date: Thu, 19 Oct 2023 09:32:32 +0200 Subject: [PATCH 3/4] #5364 : Sound : Automatically set the loop end to the end of the sound if a loop start was specified without an end --- src/components/sound.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/sound.js b/src/components/sound.js index 42bcda54c6d..6c225528a74 100644 --- a/src/components/sound.js +++ b/src/components/sound.js @@ -62,7 +62,13 @@ module.exports.Component = registerComponent('sound', { } sound.setLoop(data.loop); sound.setLoopStart(data.loopStart); - sound.setLoopEnd(data.loopEnd); + + // With a loop start specified without a specified loop end, the end of the loop should be the end of the file + if(data.loopStart != 0 && data.loopEnd == 0){ + sound.setLoopEnd(sound.buffer.duration); + } + else sound.setLoopEnd(data.loopEnd); + sound.setVolume(data.volume); sound.isPaused = false; } From 6d4804347b97ec3558ee5e7e4baaa4ca7c7835ee Mon Sep 17 00:00:00 2001 From: JonathannJacobs <102025137+JonathannJacobs@users.noreply.github.com> Date: Thu, 19 Oct 2023 23:41:38 +0200 Subject: [PATCH 4/4] #5364 : Sound : Code review changes applied. --- src/components/sound.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/sound.js b/src/components/sound.js index 6c225528a74..a2e48057cc4 100644 --- a/src/components/sound.js +++ b/src/components/sound.js @@ -34,7 +34,6 @@ module.exports.Component = registerComponent('sound', { this.pool = new THREE.Group(); this.loaded = false; this.mustPlay = false; - this.processSound = undefined; // Saved callback for the mustPlay mechanic // Don't pass evt because playSound takes a function as parameter. this.playSoundBound = function () { self.playSound(); }; @@ -67,7 +66,9 @@ module.exports.Component = registerComponent('sound', { if(data.loopStart != 0 && data.loopEnd == 0){ sound.setLoopEnd(sound.buffer.duration); } - else sound.setLoopEnd(data.loopEnd); + else { + sound.setLoopEnd(data.loopEnd); + } sound.setVolume(data.volume); sound.isPaused = false; @@ -219,9 +220,7 @@ module.exports.Component = registerComponent('sound', { if (!this.loaded) { warn('Sound not loaded yet. It will be played once it finished loading'); this.mustPlay = true; - if(processSound){ - this.processSound = processSound; - } + this.processSound = processSound; return; }