The Art of Cue-ing in p5JS

I want to know if I have a 5 second audio (or video) clip and I add a two 'cues'. One starting at 2 second mark, another starting at 3 second mark. Now if I seek the audio to 4 second mark, using 'audio.time(4);', what would happen?

  1. would both the cues execute if the audio is moved to 4 second mark.
  2. or none of them would execute.

I tried to manipulate the example given here,
p5js.org/reference/#/p5.SoundFile/addCue

This is the code that I tried, when the user clicks the canvas, the audio should seek to 4 seconds mark.

function setup() {
  background(0);
  noStroke();
  fill(255);
  textAlign(CENTER);
  //text('click to play', width/2, height/2);
  
  mySound = loadSound('assets/beat.mp3');

  // schedule calls to changeText
  mySound.addCue(0.50, changeText, "1              1" );
  mySound.addCue(1.00, changeText, " 2            2 " );
  mySound.addCue(1.50, changeText, "  3          3  " );
  mySound.addCue(2.00, changeText, "   4        4   " );
  mySound.addCue(2.50, changeText, "    5      5    " );
  mySound.addCue(3.00, changeText, "     6    6     " );
  mySound.addCue(4.00, changeText, "      7  7      " );
  mySound.addCue(5.00, changeText, "       0        " );
  //mySound.play();
}

function changeText(val) {
  //background(0);
  text(val, width/2, height/2);
}

function mouseClicked() {
  if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
    if (mySound.isPlaying() ) {
      mySound.time(4);
    } else {
      mySound.play();
    }
  }
}

Unfortunately if you try the above code in the webpage, it won't work. Can someone tell me what is going on?

Tagged:

Answers

  • So I wrote a program of my own which aligns cues on a video. Now whenever I am seeking the video forward, all the cues that are before the seeked time are getting executed. Hence the answer to my above question is definitely,

    1. would both the cues execute if the audio is moved to 4 second mark.

    If you seek to a point where there are multiple cues before, all of them will get executed. My problem now is, I don't want this behavior. The cues that were 'passed' during the seeking event should not get executed. Only the ones present after the time where the video has been seeked to should get executed, as and when their time comes.

  • @pranjchaubey -- re;

    So I wrote a program of my own

    If you have a problem demonstrated by a new program that you wrote, will you share a minimal example of the code you wrote that demonstrates the problem? This makes it much easier for forum members to help you.

Sign In or Register to comment.