Input controlled video playback in Processing

Hi! I am reading capacitive sensors with Arduino and the number of the sensor touched is communicated to Processing, at the moment it is just 1 or 2. In Processing, I am trying to play a video depending on the number of the sensor received. I need to be able to switch between the different videos during the time of playback, after it is finished, and if the same number is pressed then the video should jump back to the start.

At the moment, I can switch between the videos but only from video1 to video2, when going back from video2 to video1 I get the audio of the movie1 but it keeps displaying the last frame of the video2. I would appreciate any insight into why is this happening and how could I fix it?
This is the code in Processing


    import processing.serial.*;
    import processing.video.*;
    
    Movie video1, video2;
    
    Serial port;
    char in;
    char previousIn;
    boolean playing = false;
    //float time = 0;
    
    void setup() {  
      fullScreen(JAVA2D);
      frameRate(25);
      video1 = new Movie(this, "redFIN.mp4");
      video2 = new Movie(this, "greenFIN.mp4");
      port = new Serial(this, Serial.list()[0], 9600);
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    
    void draw() {  
      if ( port.available() > 0) {  // If data is available,
        in = char(port.read());
        print(in);
      }
    
      if (in == '1') {  
        video1.play();
        video2.stop();
        in = previousIn;
        if (in == previousIn) {
          video1.jump(0);
        }
      }
      image(video1, 0, 0, width, height);
    
    
      if (in =='2') {
        video2.play();
        video1.stop();
        in = previousIn;
        if (in == previousIn) {
          video2.jump(0);
        }
      }
      image(video2, 0, 0, width, height);
    }