Problems with my video

So, in my code I uses g4p guide in order to help me create a user interface and buttons, as I am a beginner. when the button is pressed, the video should begin to play, and the buttons disappears. The video begins to play, but the image freezes, whilst the audio continues to play. I think the video only plays when the button is pressed down, but as soon as I release the button, the video stops playing. does anyone have any suggestions to fix this?

import processing.video.*; 
import g4p_controls.*; 
Movie movie; 

void setup() {
  size(800,500);
  movie = new Movie(this, "test.mov");  
  movie.play(); 
  startPage();
}

void draw(){

}

void playAnimation() {
  if (movie.available() == true) {
    movie.read();
    next.setVisible(false);
  }
  image(movie, 0, 0, width, height);
}

void startPage(){
  createGUI();
}

this is the GUI page

public void next_click1(GButton source, GEvent event) { //_CODE_:next:626427:
  playAnimation();
} //_CODE_:next:626427:



// Create all the GUI controls. 
// autogenerated do not edit
public void createGUI(){
  G4P.messagesEnabled(false);
  G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
  G4P.setMouseOverEnabled(false);
  surface.setTitle("Sketch Window");
  next = new GButton(this, 225, 300, 350, 100);
  next.setText("next");
  next.setLocalColorScheme(GCScheme.GOLD_SCHEME);
  next.addEventHandler(this, "next_click1");
}
1 Like

I realised that the reason it didn’t work was because the draw function was empty, but I could figure out how to change it and still get the result I want.

I also tried to do this without using the G4P guide. Instead I used a mousepressed function. however, the video plays but you cant see it. how do I solve this, and also how can I hide the button after its been clicked?

import processing.video.*; 
Movie movie; 

void setup() {
  size(800,500);
  movie = new Movie(this, "test.mov");  
  movie.play(); 
}

void draw(){
  startButton();
  mousePressed();
}

void playAnimation() {
  if (movie.available() == true) {
    movie.read();
  }
  image(movie, 0, 0, width, height);
}

void startButton(){
  noStroke();
  fill(200,0,200);
  rectMode(CENTER);
  rect(400,300,200,80);
}

void mousePressed() {
  if ((mouseX < 500) && (mouseX > 300) && (mouseY > 340) && (mouseY < 260)) {
    playAnimation();
  }
}

try this

import processing.video.*; 
Movie movie; 
boolean playing;

void setup() {
  size(800,500);
  movie = new Movie(this, "test.mov");  
  movie.play(); 
}

void draw(){
  startButton();
 if (playing == true) {

    if (movie.available() == true) {

     movie.read();

   }

   image(movie, 0, 0, width, height);

  }

}

void startButton(){
  noStroke();
  fill(200,0,200);
  rectMode(CENTER);
  rect(400,300,200,80);
}

void mousePressed() {
  if ((mouseX < 500) && (mouseX > 300) && (mouseY > 340) && (mouseY < 260)) {
    playing = true;
  }
}

firstly you don’t need to call mousePressed, secondly, the way your code was it would advance one frame each time someone pressed the button. What I did was creating a variable if it is true it will play.

I hope it was helpful.

1 Like