question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

callback in addCue is called multiple times per cue time

See original GitHub issue

p5 version: 1.0.0 p5.sound version: 0.3.12 Firefox 74.0.1, Ubuntu 19.10

The callback in addCue(time, callback, [value]) is being called multiple times per cue time. The value remains the same until the next cue time.

Is this the desired behaviour?

I would have expected the callback to be called only once per cue time.

To see this, go to to the online example for addCue and modify it slightly as follows:

let mySound;
let numCalls;
function preload() {
  mySound = loadSound('assets/Damscray_DancingTiger.mp3');
}

function setup() {
  let cnv = createCanvas(100, 100);
  cnv.mousePressed(canvasPressed);
  background(220);
  text('tap to play', 10, 20);
  
  // schedule calls to changeText
  mySound.addCue(0, changeText, "hello" );
  mySound.addCue(0.5, changeText, "hello," );
  mySound.addCue(1, changeText, "hello, p5!");
  mySound.addCue(1.5, changeText, "hello, p5!!");
  mySound.addCue(2, changeText, "hello, p5!!!!!");

  mySound.onended(() => console.log(numCalls));
}

function changeText(val) {
  background(220);
  text(val, 10, 20);
  ++numCalls;
}

function canvasPressed() {
  numCalls = 0;
  mySound.play();
}

I get numCalls to be 44 or 45 and not 5. In Google Chrome it is 600 or so.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
rjpgtcommented, Apr 20, 2020

ok, thanks.

0reactions
endurance21commented, Jun 3, 2020

First install all depencies 1.npm install Then build the library 2.grunt

And thats all, you ll fins the library in Lib/ folder 🙃 @rjpgt

Read more comments on GitHub >

github_iconTop Results From Across the Web

P5 soundfile addCue is called multiple times - Libraries - Processing ...
I am using the addCue method on a p5.soundFile. I invoke this method in the setup function. The callback function i provide is...
Read more >
p5.js MediaElement addCue() Method - GeeksforGeeks
time : It is a number that specifies the time in seconds relative to the media element after which the given callback function...
Read more >
reference | addCue() - P5.js
Schedule events to trigger every time a MediaElement (audio/video) reaches a playback cue point. Accepts a callback function, a time (in seconds) at...
Read more >
Callback function called multiple times - javascript
I am trying to make calendar for my application, when i click on date for first time, callback method is getting called 1...
Read more >
Implementing Cue Points Programmatically
Without this condition you would see that each cue point would be acted upon twice, the second time with no defined elements in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found