How to run video from the start with switch/case method?

edited June 2015 in Library Questions

Hello, I'm working on a projects where I take data from arduino and with the code bellow I'm changing the videos in processing regarding the data received. The problem is that the videos are starting from the middle.

How to tell processing that I want my videos to start from the exact first frame? :)

I have the same functionality that works well with the if/else function, but I'm receiving GStream-CRITICAL error there, so I'm curious how to do this right with the switch/case function.

Look forward to receive some comments. Thanks in advance, Elena

import processing.serial.*; 
import processing.video.*;

Serial port; 
Movie myMovie0;
Movie myMovie1; 
Movie myMovie2;
Movie myMovie3;
Movie myMovie4;
Movie myMovie5;
Movie myMovie6;
Movie myMovie7;
int val=0;


void setup() {
  size(1024, 768); 
  myMovie0 = new Movie(this, "0.mp4"); 
  myMovie0.loop(); 
  myMovie1 = new Movie(this, "7.mp4"); 
  myMovie1.loop(); 
  myMovie2 = new Movie(this, "6.mp4"); 
  myMovie2.loop(); 
  myMovie3 = new Movie(this, "5.mp4"); 
  myMovie3.loop(); 
  myMovie4 = new Movie(this, "4.mp4"); 
  myMovie4.loop();
  myMovie5 = new Movie(this, "3.mp4"); 
  myMovie5.loop(); 
  myMovie6 = new Movie(this, "2.mp4"); 
  myMovie6.loop(); 
  myMovie7 = new Movie(this, "1.mp4"); 
  myMovie7.loop();
  port = new Serial(this, "COM4", 9600); 
}

void serialEvent(Serial port) {
  val = port.read();
  println( "Raw Input:" + val);
}

void draw() { 

switch(val){
  case 48:
  myMovie0.play();
  image(myMovie0, 0, 0);
  break;
  case 49:  
  myMovie1.play();
  image(myMovie1, 0, 0); 
  break;  
  case 50:
  myMovie2.play();
  image(myMovie2, 0, 0);
  break;
  case 51:
  myMovie3.play();
  image(myMovie3, 0, 0);
  break;
  case 52:
  myMovie4.play();
  image(myMovie4, 0, 0);
  break;
  case 53:
  myMovie5.play();
  image(myMovie5, 0, 0);
  break;
  case 54:
  myMovie6.play();
  image(myMovie6, 0, 0);
  break;
  case 55:
  myMovie7.play();
  image(myMovie7, 0, 0);
  break;
}
}

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

Answers

  • Thanks GoToLoop, but when I change it from "play" to "stop" in void loop it runs only one session. When I try the with "loop" in the switch/case section it runs from the beginning only once, but the next sessions are starting random again. Any solutions?

    void setup() {
      size(1024, 768); 
      myMovie0 = new Movie(this, "0.mp4"); 
      myMovie0.stop();
    
    switch(val){
      case 48:
      myMovie0.loop();
      image(myMovie0, 0, 0);
      break;
    
Sign In or Register to comment.