import processing.serial.*;
Serial myCommChannel;
import processing.video.*;
Movie Video01;
Movie Video02;
Movie Video03;
Movie Video04;
Movie Video05;
Movie Video06;
Movie Video07;
float startPlayTimeVideo01 = 0.0;
float startPlayTimeVideo02 = 0.0;
float startPlayTimeVideo03 = 0.0;
float startPlayTimeVideo04 = 0.0;
float startPlayTimeVideo05 = 0.0;
float startPlayTimeVideo06 = 0.0;
float startPlayTimeVideo07 = 0.0;
boolean isPlayingVideo01 = false;
boolean isPlayingVideo02 = false;
boolean isPlayingVideo03 = false;
boolean isPlayingVideo04 = false;
boolean isPlayingVideo05 = false;
boolean isPlayingVideo06 = false;
boolean isPlayingVideo07 = false;
boolean isCurrentlyPlaying = false;
char lastSerialInput = 'z';
byte trackID = 0;
void setup() {
fullScreen();
printArray(Serial.list());
myCommChannel = new Serial(this, Serial.list()[0], 9600);
Video01 = new Movie(this, "video01.mp4");
Video02 = new Movie(this, "video02.mp4");
Video03 = new Movie(this, "video03.mp4");
Video04 = new Movie(this, "video04.mp4");
Video05 = new Movie(this, "video05.mp4");
Video06 = new Movie(this, "video06.mp4");
Video07 = new Movie(this, "video07.mp4");
myCommChannel.write('1');
}
void draw() {
switch (trackID) {
case 1:
image(Video01, 0, 0, width, height);
checkPlayStatusVideo01();
break;
case 2:
image(Video02, 0, 0, width, height);
checkPlayStatusVideo02();
break;
case 3:
image(Video03, 0, 0, width, height);
checkPlayStatusVideo03();
break;
case 4:
image(Video04, 0, 0, width, height);
checkPlayStatusVideo04();
break;
case 5:
image(Video05, 0, 0, width, height);
checkPlayStatusVideo05();
break;
case 6:
image(Video06, 0, 0, width, height);
checkPlayStatusVideo06();
break;
case 7:
image(Video07, 0, 0, width, height);
checkPlayStatusVideo07();
break;
}
if (isCurrentlyPlaying == false) {
char inputCommandChar = myCommChannel.readChar();
if (inputCommandChar != lastSerialInput) {
switch(inputCommandChar) {
case 'a':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile01();
myCommChannel.clear();
break;
case 'b':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile02();
myCommChannel.clear();
break;
case 'c':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile03();
myCommChannel.clear();
break;
case 'd':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile04();
myCommChannel.clear();
break;
case 'e':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile05();
myCommChannel.clear();
break;
case 'f':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile06();
myCommChannel.clear();
break;
case 'g':
println(inputCommandChar);
isCurrentlyPlaying = true;
lastSerialInput = inputCommandChar;
playVideoFile07();
myCommChannel.clear();
break;
default:
break;
}
}
}
myCommChannel.clear();
}
void movieEvent(Movie m) {
m.read();
}
void playVideoFile01() {
if (isPlayingVideo01 == false ) {
startPlayTimeVideo01 = millis();
isPlayingVideo01 = true;
trackID = 1;
Video01.play();
}
}
void checkPlayStatusVideo01() {
if (isPlayingVideo01 == true) {
if ( (millis() - startPlayTimeVideo01) >= (Video01.duration()*1000) ) {
isPlayingVideo01 = false;
isCurrentlyPlaying = false;
Video01.stop();
println("offVT01");
myCommChannel.write('<');
myCommChannel.write('2');
myCommChannel.write('+');
}
}
}
void playVideoFile02() {
if (isPlayingVideo02 == false ) {
startPlayTimeVideo02 = millis();
isPlayingVideo02 = true;
trackID = 2;
Video02.play();
}
}
void checkPlayStatusVideo02() {
if (isPlayingVideo02 == true) {
if ( (millis() - startPlayTimeVideo02) >= (Video02.duration()*1000) ) {
isPlayingVideo02 = false;
isCurrentlyPlaying = false;
Video02.stop();
println("offVT02");
myCommChannel.write('<');
myCommChannel.write('3');
}
}
}
void playVideoFile03() {
if (isPlayingVideo03 == false ) {
startPlayTimeVideo03 = millis();
isPlayingVideo03 = true;
trackID = 3;
Video03.play();
}
}
void checkPlayStatusVideo03() {
if (isPlayingVideo03 == true) {
if ( (millis() - startPlayTimeVideo03) >= (Video03.duration()*1000) ) {
isPlayingVideo03 = false;
isCurrentlyPlaying = false;
Video03.stop();
println("offVT03");
myCommChannel.write('<');
myCommChannel.write('4');
}
}
}
void playVideoFile04() {
if (isPlayingVideo04 == false ) {
startPlayTimeVideo04 = millis();
isPlayingVideo04 = true;
trackID = 4;
Video04.play();
}
}
void checkPlayStatusVideo04() {
if (isPlayingVideo04 == true) {
if ( (millis() - startPlayTimeVideo04) >= (Video04.duration()*1000) ) {
isPlayingVideo04 = false;
isCurrentlyPlaying = false;
Video04.stop();
println("offVT04");
myCommChannel.write('<');
myCommChannel.write('5');
}
}
}
void playVideoFile05() {
if (isPlayingVideo05 == false ) {
startPlayTimeVideo05 = millis();
isPlayingVideo05 = true;
trackID = 5;
Video05.play();
}
}
void checkPlayStatusVideo05() {
if (isPlayingVideo05 == true) {
if ( (millis() - startPlayTimeVideo05) >= (Video05.duration()*1000) ) {
isPlayingVideo05 = false;
isCurrentlyPlaying = false;
Video05.stop();
println("offVT05");
myCommChannel.write('<');
myCommChannel.write('6');
}
}
}
void playVideoFile06() {
if (isPlayingVideo06 == false ) {
startPlayTimeVideo06 = millis();
isPlayingVideo06 = true;
trackID = 6;
Video06.play();
}
}
void checkPlayStatusVideo06() {
if (isPlayingVideo06 == true) {
if ( (millis() - startPlayTimeVideo06) >= (Video06.duration()*1000) ) {
isPlayingVideo06 = false;
isCurrentlyPlaying = false;
Video06.stop();
println("offVT06");
myCommChannel.write('<');
myCommChannel.write('7');
}
}
}
void playVideoFile07() {
if (isPlayingVideo07 == false ) {
startPlayTimeVideo07 = millis();
isPlayingVideo07 = true;
trackID = 7;
Video07.play();
}
}
void checkPlayStatusVideo07() {
if (isPlayingVideo07 == true) {
if ( (millis() - startPlayTimeVideo07) >= (Video07.duration()*1000) ) {
isPlayingVideo07 = false;
isCurrentlyPlaying = false;
Video07.stop();
println("offVT07");
myCommChannel.write('<');
myCommChannel.write('1');
myCommChannel.write('+');
}
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.