# Question about infrared sensor triggered video on Raspberry Pi

**URL:** https://discourse.processing.org/t/question-about-infrared-sensor-triggered-video-on-raspberry-pi/38696
**Category:** Processing for Pi
**Created:** [September 9, 2022, 10:28pm UTC](https://discourse.processing.org/t/question-about-infrared-sensor-triggered-video-on-raspberry-pi/38696 "2022-09-09T22:28:02Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![nitrocaphane](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nitrocaphane/32/16885_2.png) [@nitrocaphane](https://discourse.processing.org/u/nitrocaphane)
#### Post date: [September 9, 2022, 10:28pm UTC](https://discourse.processing.org/t/question-about-infrared-sensor-triggered-video-on-raspberry-pi/38696/1 "2022-09-09T22:28:02Z")

</div>

Hi, I’m using an IR sensor to play a video in Processing on Raspberry Pi.

mouth0 = a video of a closed mouth  
mouth1 = a video of the mouth singing

Once triggered, I want mouth1 to play until the entire clip finishes, but with the current code, it only keeps playing the video while my hand is actively triggering the sensor. When I remove my hand, it stops playing immediately.

How can I keep the clip playing until it’s done?  
Thank you.

```auto
import processing.video.*;
import processing.io.*;

Movie mouth0, mouth1;
boolean m0 = true;
boolean m1 = false;
int VideoPlaying;

void setup() {
    noCursor();
    background(0);
    
  GPIO.pinMode(17, GPIO.INPUT_PULLUP);
  
  size(480, 270);
  background(0);
  mouth0 = new Movie(this, "mouth0.mov");
  mouth1 = new Movie(this, "mouth1.mov");
}

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

void draw() {
    if (GPIO.digitalRead(17) == GPIO.LOW) {
    VideoPlaying = 1 ;
    println(VideoPlaying);
  }else{
    VideoPlaying = 0 ;
    println(VideoPlaying);
  }
  
  toogle();
  //println("m0:"+m0);
  //println("m1:"+m1);
  if (m1) {
    mouth0.stop();
    mouth1.play(); 
    image(mouth1, 0, 0, width, height);
    println("mouth1 playing");
    if (abs(mouth1.duration()-mouth1.time()) < .05){
      m1 = false; 
      mouth1.stop();
      VideoPlaying = 0;
    }
  }
  if (m0) {
    mouth0.loop();
    image(mouth0, 0, 0, width, height);
    println("mouth0 playing");
  }
}

void toogle() {
  if (VideoPlaying == 0) {
    m0 = true;
    m1 = false;
  }
  if (VideoPlaying == 1) {
    m0 = false;
    m1 = true;
  }
}

```
