how do I disable keyboard input when the video is playng?

Viewed 54

I am making an application where a main video runs in an infinite loop. When the user presses a key, say 'a', the video associated with it plays and the main video runs in background. It's oky if it's not paused or stop because the main video has no sound in it.

The issue is I want to disable the keyboard input while the user's video is still playing. I am unable to do that. In my current code, when the video is playing, if the user presses another key, then the video associated with it starts playing over the video that is already playing.

Can anyone help me figure out how to disable the keyboard input when the video is already playing? Please help me with the logic. Thanks in advance.

import processing.video.*;
import processing.sound.*;
Movie vid1, vid2, vid0;

boolean b1, b2 = false;

void setup() 
{
  size(1920, 1080);  
  vid1  = new Movie(this, "vid-01.mp4");
  vid2  = new Movie(this, "fhv-2.mp4");
  vid0 = new Movie (this, "main-vid-0.mp4"); 
  frameRate(30);
  //main.loop();
  //main.play();
  //main.stop();
  //main.loop();
}

void draw() 
{
  background(0);
  
  image(vid0, 0, 0);
  vid0.loop();
  vid0.volume(10);
  
  if (b1 == true)
  {
    image(vid1, 0, 0);
    if (vid1.time() ==  vid1.duration())
    {
      vid1.stop();
      b1=false;
    }
    else{
      vid0.volume(0);
      //key = 0;
    }
  } 
  
  //vid2
  if (b2 == true)
  {
    image(vid2, 0, 0);
    if (vid2.time() ==  vid2.duration())
    {
      vid2.stop();      
      b2=false;
    }
    else{
      vid0.volume(0);
      //key = 0;
    }
  }

}

void keyPressed()
{
  if (key == 'a' || key ==  'A')
  {
    //vid0.volume(0);
    vid1.play();  
    b1 = true; 
    }
   
   if (key == 'b'|| key ==  'B'){
     vid2.play();
     b2 = true;
   }
   
   
   
}

void movieEvent(Movie m) 
{
  m.read();
}
1 Answers

You can also use the time() and duration() functions of a Movie object, to check whether a vid has not started or it has finished before allowing a key to be pressed.

void draw() {
    background(0);
  
    image(vid0, 0, 0);
    vid0.loop();
    vid0.volume(10);

}

void keyPressed() {
    if((vid1.time() == 0.0 || vid1.time() == vid1.duration()) && (vid2.time() == 0.0 || vid2.time() == vid2.duration())){
        if (key == 'a' || key ==  'A'){
             vid0.pause();
             //vid0.volume(0);
             vid1.play();  
        }
   
        if (key == 'b'|| key ==  'B'){
            vid0.pause();
            vid2.play();
        }
    }
}
Related