mirror of
https://github.com/scratchfoundation/scratch-audio.git
synced 2025-01-08 13:51:58 -05:00
handle missing sounds
This commit is contained in:
parent
73dc7a3d40
commit
c8d194b951
1 changed files with 12 additions and 4 deletions
16
src/index.js
16
src/index.js
|
@ -23,7 +23,7 @@ function AudioEngine (sounds) {
|
||||||
this.effectsNode.chain(this.delay, this.panner, this.reverb, Tone.Master);
|
this.effectsNode.chain(this.delay, this.panner, this.reverb, Tone.Master);
|
||||||
|
|
||||||
// reset effects to their default parameters
|
// reset effects to their default parameters
|
||||||
// this.clearEffects();
|
this.clearEffects();
|
||||||
|
|
||||||
// load sounds
|
// load sounds
|
||||||
|
|
||||||
|
@ -66,19 +66,24 @@ AudioEngine.prototype.loadSounds = function (sounds) {
|
||||||
|
|
||||||
AudioEngine.prototype.playSound = function (index) {
|
AudioEngine.prototype.playSound = function (index) {
|
||||||
var player = this.soundPlayers[index];
|
var player = this.soundPlayers[index];
|
||||||
if (player.buffer.loaded) {
|
if (player && player.buffer.loaded) {
|
||||||
player.start();
|
player.start();
|
||||||
} else {
|
} else {
|
||||||
// if the sound has not yet loaded, wait and try again
|
// if the sound has not yet loaded, wait and try again
|
||||||
log.warn('sound ' + index + ' not loaded yet');
|
log.warn('sound ' + index + ' not loaded yet');
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
this.playSound(index);
|
this.playSound(index);
|
||||||
}, 100);
|
}.bind(this), 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioEngine.prototype.getSoundDuration = function (index) {
|
AudioEngine.prototype.getSoundDuration = function (index) {
|
||||||
return this.soundPlayers[index].buffer.duration;
|
var player = this.soundPlayers[index];
|
||||||
|
if (player && player.buffer.loaded) {
|
||||||
|
return player.buffer.duration;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
AudioEngine.prototype.playNoteForBeats = function (note, beats) {
|
AudioEngine.prototype.playNoteForBeats = function (note, beats) {
|
||||||
|
@ -172,6 +177,9 @@ AudioEngine.prototype.changeEffect = function (effect, value) {
|
||||||
|
|
||||||
AudioEngine.prototype._setPitchShift = function (value) {
|
AudioEngine.prototype._setPitchShift = function (value) {
|
||||||
this.pitchShiftRatio = value;
|
this.pitchShiftRatio = value;
|
||||||
|
if (!this.soundPlayers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (var i=0; i<this.soundPlayers.length; i++) {
|
for (var i=0; i<this.soundPlayers.length; i++) {
|
||||||
var s = this.soundPlayers[i];
|
var s = this.soundPlayers[i];
|
||||||
if (s) {
|
if (s) {
|
||||||
|
|
Loading…
Reference in a new issue