processing / p5.sound.js-pre-release

GNU Lesser General Public License v2.1
4 stars 1 forks source link

`loadSound` Callbacks Not Triggering #26

Open SableRaf opened 2 weeks ago

SableRaf commented 2 weeks ago

The loadSound() function's callbacks (success, error, and whileLoading) aren't being triggered as expected in the p5.sound prerelease. This prevents handling events during the loading process and confirming a successful or failed load.

Function Signature

loadSound(path, [successCallback], [errorCallback], [whileLoading])

Example

let player;

function preload() {
  player = loadSound(
    'https://tonejs.github.io/audio/berklee/gong_1.mp3', 
    () => { console.log("success"); }, // Success callback
    () => { console.log("failure"); },  // Error callback
    (progress) => { console.log(`Loading: ${progress * 100}%`); }  // While loading callback
    );
}

function setup() {
  createCanvas(100, 100);
  background(220);
}

function mousePressed() {
  player.play();
}

Expected Behavior

Actual Behavior

limzykenneth commented 2 weeks ago

@tmartinez88 this._decrementPreload() needs to be manually called when loading completes for preload() to work with loadSound(). See docs here