Hello, I have been coding a progress bar using some examples that I found. The bar is almost done but it doesn't constantly update. Can someone assist me in getting it to update while the video is playing? https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar#latest `
void setup() {
size(1280, 360);
cp5 = new ControlP5(this);
background(0);
// Load and play the video in a loop
movie = new Movie(this, "video.mov");
movie.play();
movie.speed(speed);
//Progress Bar
ProgressBar p;
p = new ProgressBar(cp5, "progress");
p.setPosition(130, 345).setSize(350, 10).setRange(0, (int)
movie.duration()).listen(true);
//callback listener for Timeline object
p.addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
if(theEvent.getAction() == ControlP5.ACTION_PRESS) {
float x = theEvent.getController().getPointer().x();
float a1 = 0;
float a2 = theEvent.getController().getWidth();
float b1 = theEvent.getController().getMin();
float b2 = theEvent.getController().getMax();
float val = map(x,a1,a2,b1,b2);
theEvent.getController().setValue(val);
println("now change movie time to ", val, movie.time());
movie.jump((float) val);
}
}
}
);
// a toggle to switch between play and pause mode
cp5.addToggle("play")
.setPosition(10,375)
.setSize(50,19)
.getCaptionLabel().align(CENTER,CENTER);
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
if (play) {
// update the progressBar value/position
// replace with audio-track position: progress = player.position();
if (movie.available()) movie.read();
progress = (int) movie.time();
}
}
class ProgressBar extends Controller<ProgressBar> {
public ProgressBar(ControlP5 theControlP5, String theName) {
super(theControlP5, theName);
setView(new ControllerView<ProgressBar>() {
public void display(PGraphics pg, ProgressBar c) {
pg.fill(!isMouseOver() ? c.getColor().getForeground():c.getColor().getActive());
pg.rect(0, 0, c.getWidth(), c.getHeight());
float val = map(c.getValue(),c.getMin(), c.getMax(), 0, c.getWidth());
pg.fill(255);
pg.rect(0, 0, val, c.getHeight());
}
}
);
}
public ProgressBar setValue(float theValue) {
return super.setValue(constrain(theValue, getMin(), getMax()));
}
public ProgressBar setRange(int theStart, int theEnd) {
_myMin = theStart;
_myMax = theEnd;
return this;
}
}`