Status bar with movie and ControlP5

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

Answers

  • Hello,

    Can anyone help please?

    I really need to fix a solution for that need not be this way, it can be based on another example. What you need is to have a resource to advance the video to obtain the best move faster (like youtube).

    I will try to explain better idea ... We are developing an option in the Project (which has multiple options), where we have the "storytelling" of illustrated stories.

    It works like this: Choose a Story, Snow White, Cinderella, etc ...

    Earlier passes a short video about the history (so you can move the resource) unless you want to see the whole story.

    Then through figures representing each phrase, putting the story goes, the dynamics of interaction can be from 2 to 5 figures, if you miss the correct option, displays a warning message and asks new choice.

    The idea of ​​the project for now, is for staff with motor difficulty, and who are not literate, but who recognize the story through symbols.

    The idea is then we can extend literacy aid, which you can use as well with children not alfatizadas, and literate, we will extend the use of memory game, educational games, etc ...

    Too bad that you can not quite understand what I'm trying to say, the translator does not do well what we wanted to say, but at least we have this helps to communicate, without it would be impossible..

    Below is an print some screens, trying to get better idea of how is the project.

    Menu01 Menu02 Menu03 Menu03b Menu06

    Thank you all....

  • Hello,

    I was looking in the wrong place ... in Video Processing documentation is the solution.

    Is this command to change the position of the film:

    movie1.jump ((float) val);

    Thank you,

Sign In or Register to comment.