Hello guys,
I'm trying to put a bar to control the time / position when running a film, based on this example: https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar
To show the bar as the elapsed time, ran regular ...
But how do if you want to advance the film? It did not work when I tried movie.position () (as sound).
Someone could give a tip, or where can I find some documentation on the subject?
Below the code I am using as an example:
import controlP5.*;
import processing.video.*;
ControlP5 cp5;
Movie movie1;
float md, mt;
int progress;
boolean play;
void setup() {
size(600, 400);
cp5 = new ControlP5(this);
movie1 = new Movie(this, "D:/Projetos/Videos/Branca_de_Neve.mpg");
movie1.play();
ProgressBar p; // custom Controller class, see implementation below
p = new ProgressBar(cp5, "progress"); // "progress" here will be linked to variable progress
//p.setPosition(100, 300).setSize(200, 20).setRange(0, 1000).listen(true);
p.setPosition(70, 330).setSize(350, 10).setRange(0, (int) movie1.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, movie1.time());
//movie1.position(); //????
}
}
}
);
// a toggle to switch between play and pause mode
cp5.addToggle("play")
.setPosition(10,375)
.setSize(50,19)
.getCaptionLabel().align(CENTER,CENTER);
}
void draw() {
background(0);
if (play) {
// update the progressBar value/position
// replace with audio-track position: progress = player.position();
if (movie1.available()) movie1.read();
image(movie1, 70, 40);
//progress++;
progress = (int) movie1.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;
}
}
Thanks for listening