Skip to content

Commit

Permalink
#5364 Bugfix : Sound : processSound callback saved and used with load…
Browse files Browse the repository at this point in the history
…ed + mustPlay (#5365)

* #5364 Bugfix : The processSound callback given to playSound() before the sound was loaded will be called when loaded and not ignored anymore.

* #5364 : Sound : Added API for reaching THREE.Audio.loopStart() and loopEnd()

* #5364 : Sound : Automatically set the loop end to the end of the sound if a loop start was specified without an end

* #5364 : Sound : Code review changes applied.
  • Loading branch information
JonathannJacobs authored Oct 23, 2023
1 parent 0e2399e commit ff6da4b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -58,6 +60,16 @@ module.exports.Component = registerComponent('sound', {
sound.setRolloffFactor(data.rolloffFactor);
}
sound.setLoop(data.loop);
sound.setLoopStart(data.loopStart);

// 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){

Check failure on line 66 in src/components/sound.js

View workflow job for this annotation

GitHub Actions / Test Cases (16.x, latest)

Expected space(s) after "if"

Check failure on line 66 in src/components/sound.js

View workflow job for this annotation

GitHub Actions / Test Cases (16.x, latest)

Expected '!==' and instead saw '!='

Check failure on line 66 in src/components/sound.js

View workflow job for this annotation

GitHub Actions / Test Cases (16.x, latest)

Expected '===' and instead saw '=='

Check failure on line 66 in src/components/sound.js

View workflow job for this annotation

GitHub Actions / Test Cases (16.x, latest)

Missing space before opening brace

Check failure on line 66 in src/components/sound.js

View workflow job for this annotation

GitHub Actions / Test Cases (16.x, latest)

Trailing spaces not allowed
sound.setLoopEnd(sound.buffer.duration);
}
else {

Check failure on line 69 in src/components/sound.js

View workflow job for this annotation

GitHub Actions / Test Cases (16.x, latest)

Closing curly brace does not appear on the same line as the subsequent block
sound.setLoopEnd(data.loopEnd);
}

sound.setVolume(data.volume);
sound.isPaused = false;
}
Expand All @@ -80,7 +92,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);
});
}
Expand Down Expand Up @@ -208,6 +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;
this.processSound = processSound;
return;
}

Expand All @@ -231,6 +244,7 @@ module.exports.Component = registerComponent('sound', {
}

this.mustPlay = false;
this.processSound = undefined;
},

/**
Expand Down

0 comments on commit ff6da4b

Please sign in to comment.