Remote Control/ Play Video
in
Integration and Hardware
•
1 year ago
Hi,
I have a problem with this code. I have a remote control and I can send information from the usb port by using a RC-5 code receiver. I can see that different data is sent once I press different buttons. Then I want to play a certain video when I press each button. For example I want to play video 1 when I press button 1 and video 2 when I press button 2.
I found these codes; I can play the video with this code.
-----------------------------------------------------------
import processing.video.*;
Movie mov_1,mov_a,nowPlaying;
float f;
float movSpeed;
void setup(){
size(640,480,P2D);
background(0);
mov_1 = new Movie(this, "tation.mov");
mov_a = new Movie(this, "drawing.mov");
nowPlaying = mov_1;
nowPlaying.loop();
}
void draw(){
background(0);
image(nowPlaying,0,0,width,height);
}
void movieEvent(Movie _mov){
_mov.read();
}
void keyPressed(){
if (key == 'a'){
nowPlaying = mov_1;
nowPlaying.jump(0);
nowPlaying.loop();
}
if (key == 'b'){
nowPlaying = mov_a;
nowPlaying.jump(0);
nowPlaying.loop();
}
}
------------------------------------------------------
With the second code I can see that there is a different data that is sent from the serial port
------------------------------------------------------
import processing.serial.*;
Serial myPort; // The serial port:
void setup() {
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
while (myPort.available() > 0) {
char inByte = myPort.readChar();
println(inByte);
}
}
----------------------------------------------------
Then I combined these two codes to be able to play a video once there is a different information sent ( different buttons are pressed).
--------------------------------------------------
import processing.serial.*;
import processing.video.*;
Serial myPort; // The serial port:
Movie mov_1,mov_a,nowPlaying;
float f;
float movSpeed;
void setup() {
size(640,480,P2D);
background(0);
mov_1 = new Movie(this, "tation.mov");
mov_a = new Movie(this, "drawing.mov");
nowPlaying = mov_1;
nowPlaying.loop();
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw() {
while (myPort.available() > 0) {
char inByte = myPort.readChar();
println(inByte);
if (inByte == '1') {
nowPlaying = new Movie(this, "tation.mov");
nowPlaying.loop();
}
if (inByte == '2') {
nowPlaying = mov_a;
nowPlaying.loop();
}
background(0);
image(nowPlaying,0,0,width,height);
}
}
--------------------------------------------------
But I have a problem with this code,
I can see that different data is sent from the remote control from the serial monitor. Once I press button 1, video 1 appears and the same happens for button 2 and video 2. However I can only see the first frame of the videos. When I press again I see another frame. I need the videos to play in a loop. How can I solve this problem?
Thanks a lot.
1