# Video switch not on Loop

**URL:** <https://discourse.processing.org/t/video-switch-not-on-loop/17407>\
**Category:** Libraries\
**Created:** [January 29, 2020, 8:37am UTC](https://discourse.processing.org/t/video-switch-not-on-loop/17407 "2020-01-29T08:37:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanoevelenstef](https://avatars.discourse-cdn.com/v4/letter/v/41988e/32.png) [@vanoevelenstef](https://discourse.processing.org/u/vanoevelenstef)\
**Post date:** [January 29, 2020, 8:37am UTC](https://discourse.processing.org/t/video-switch-not-on-loop/17407/1 "2020-01-29T08:37:42Z")

</div>

I compiled this code from some sources and it works (what is a big deal) but my video stops after it plays and I would like it to play on loop. Tried `loop();` function but didn’t work. Any suggestions?

```auto
import processing.video.*;
Movie theMov; 
int VideoPlaying;

int time;
boolean leftIsPressed, shiftIsPressed, rightIsPressed;
boolean keyAction;

// Step #1 : Enter Boolean + Vid + next number + =false; ================================================================
boolean Vid1 = false;
boolean Vid2 = false;
boolean Vid3 = false;
boolean Vid4 = false;
boolean Vid5 = false;

// Step #2 : Create new Movie + Video + _next number; ================================================================
Movie Video_01; 
Movie Video_02; 
Movie Video_03;
Movie Video_04;
Movie Video_05;

void setup() { // Step #3 : Create new entry with "Video_Number" = new Movie(this, "NAME OF VIDEO.MOV"); } ================================================================
  size(displayWidth, displayHeight);
    //fullScreen();
  time = millis();
  Video_01 = new Movie(this, "test1.mov");
  Video_02 = new Movie(this, "test2.mp4");
  Video_03 = new Movie(this, "test3.mov");
  Video_04 = new Movie(this, "test4.mov");
  Video_05 = new Movie(this, "test5.mov");
}

void draw() { // Step #4 : Enter new (VidNEXTNUMBER) with { video_number of Step #3 }; ================================================================
  background(0);
  fill(255);
  textSize(100);
    textAlign(CENTER, CENTER);
  text("START VIDEO BY PRESSING ANY KEY", 0, 0, width, height);

  toogle();
  if (Vid1) {
    video_01();
  }
  if (Vid2) {
    video_02();
  }
  if (Vid3) {
    video_03();
  }
  if (Vid4) {
    video_04();
  }
  if (Vid5) {
    video_05();
  }
}

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

void keyPressed() { // Step #5 : Create new entry as : if (key == NEW_KEY { VideoPlaying = NUMBER_SAMEAS_VIDEO_NUMBER; println(Videoplaying);} ================================================================
  
  if (key == ESC) {
    key = 0; // ESCAPE doesn't close the sketch.
  }

  if (key == 'a') { // Video 01
    VideoPlaying = 1 ;
    println(VideoPlaying);
  }
  if (key == 'z') { // Video 02
    VideoPlaying = 2 ;
    println(VideoPlaying);
  }
  if (key == 'e') { // Video 03
    VideoPlaying = 3 ;
    println(VideoPlaying);
  }
  if (key == 'r') { // Video 04
    VideoPlaying = 4 ;
    println(VideoPlaying);
  }
  if (key == ENTER) { // Video 04
    VideoPlaying = 5 ;
    println(VideoPlaying);
  }
}

void video_01() { // Step #6 : Create new entry as : void video_NEXTNUMBER() { println("VideoNUMBER"); all other Video_XX.stop(); background(O); Video_NEWNUMBER(); background(0); image()Video_NEWNUMBER, 0, 0, width, height);} ================================================================
println("time");
  println("video1");
  Video_02.stop();
  Video_03.stop(); 
  Video_04.stop();
    Video_05.stop();
  background(0);
  Video_01.play();
  background(0);
  image(Video_01, 0, 0, width, height);
}
void video_02() {
  println("video2");
  Video_01.stop();
  Video_03.stop(); 
  Video_04.stop();
    Video_05.stop();
  background(0);
  Video_02.play();
  image(Video_02, 0, 0, width, height);
}
void video_03() {
  println("video3");
  Video_01.stop();
  Video_02.stop();
  Video_04.stop();
    Video_05.stop();
  background(0);
  Video_03.play();
  image(Video_03, 0, 0, width, height);
}
void video_04() {
  println("video4");
  Video_01.stop();
  Video_02.stop();
  Video_03.stop();
  Video_05.stop();
  background(0);
  Video_04.play();
  image(Video_04, 0, 0, width, height);
}
void video_05() {
  println("video5");
  Video_01.stop();
  Video_02.stop();
  Video_03.stop();
  Video_04.stop();
  background(0);
  Video_05.play();
  image(Video_05, 0, 0, width, height);
}

void toogle() { // Step #7 : Create new entry as : if (VideoPlaying == NEWNUMBER) { Complete list of all "VIDx = false" + "VID_NEWNUMBER = true" }; ================================================================
  if (VideoPlaying == 1) {
    Vid1 = true;
    Vid2 = false;
    Vid3 = false;
    Vid4 = false;
    Vid5 = false;
  }

  if (VideoPlaying == 2) {
    Vid1 = false;
    Vid2 = true;
    Vid3 = false;
    Vid4 = false;
    Vid5 = false;

  }

  if (VideoPlaying == 3) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = true;
    Vid4 = false;
    Vid5 = false;
  }

  if (VideoPlaying == 4) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = false;
    Vid4 = true;
    Vid5 = false;
  }
  
  if (VideoPlaying == 5) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = false;
    Vid4 = false;
    Vid5 = true;
  }
}

```

---

<div class="post-metadata">

**Author:** ![BrokenCode](https://avatars.discourse-cdn.com/v4/letter/b/9de0a6/32.png) [@BrokenCode](https://discourse.processing.org/u/BrokenCode)\
**Post date:** [January 29, 2020, 11:03am UTC](https://discourse.processing.org/t/video-switch-not-on-loop/17407/2 "2020-01-29T11:03:03Z")

</div>

Simply write `.loop()` :

```auto
void video_01() { println("time");
  println("video1");
  background(0); // this is not necessary
  Video_01.loop(); // ======= HERE
  background(0); // this is not necessary
  image(Video_01, 0, 0, width, height);
}

```

It works for me
