我不知道为什么我无法让我的视频键盘工作。我编写了我的代码,这样当你按任意键时,Processing会播放从数组中随机选择的视频。
//forum.processing.org/two/discussion/6590/play-a-random-list-of-videos-by-keypress-exhaust
boolean sketchFullScreen() {
return true;
}
import processing.video.*;
String[] moviesNames = {
"1.mov", "2.mov", "3.mov", "4.mov","5.mov", "6.mov", "7.mov","8.mov", "9.mov", "10.mov","11.mov",
"12.mov", "13.mov","14.mov", "15.mov", "16.mov","17.mov", "18.mov", "19.mov","20.mov", "21.mov", "22.mov","23.mov","24.mov", "25.mov", "26.mov",
};
int index = int(random(moviesNames.length));
Movie[] movies;
//Movie mov_a, mov_b, mov_c, mov_d, nowPlaying;
Boolean isPlaying = false;
void setup() {
size(displayWidth, displayHeight, P2D);
background(0);
frameRate = 60;
movies = new Movie[moviesNames.length];
for (int i = 0; i < moviesNames.length; i++) {
movies[i] = new Movie(this, moviesNames[i]);
}
}
void draw() {
background(0);
if(isPlaying){
image(movies[index], 0, 0, width, height);
}
}
void movieEvent(Movie _mov) {
_mov.read();
}
void keyPressed() {
isPlaying = true;
int k = keyCode;
if (k >= 'A' && k <= 'Z'){
pickRandomVideoIndex();
}
}
void keyReleased(){
isPlaying = false;
movies[index].stop();
}
void pickRandomVideoIndex() {
if (movies.length <= 1) {
return;
}
//movies[index].pause(); // pause current video.
int rnd = index; // keep picking a new index till got a diff. 1:
while ( rnd == index ){
rnd = (int) random(movies.length);
}
// assign newly picked random value to index:
index = rnd;
movies[index].loop(); // and start playing it.
}
在按下多个按键时,我非常乐意帮助确定如何防止视频互相播放。一旦你按下一个以上的键,或者输入的速度非常快,那么一切都会崩溃。