need processing to trigger either audio clip or video clip ( using random function )

edited November 2014 in How To...

Hey guys,
so here is my situation - i have got two working processing codes ( only because of all the help i received on this forum, thanks to GoToLoop ). The first code triggers off video clips based on a particular string input. The second code does exactly the same thing, but triggers off audio clips instead. What i need to do now is somehow merge both the codes such that, when i type in a string input ( say 'red' ), processing will, at random, either play the video clip, or the audio clip that is related to that particular string input. I hope i have been clear enough.. [-O<

this is the code for triggering video clips -

import processing.video.Movie;

static final int QTY = 3;
final Movie[] movies = new Movie[QTY];
int idx;
String typing = "";
String saved = "";

void setup() { 
  size(1440, 900, JAVA2D);
  frameRate(30);
  noSmooth();

  movies[0] = new Movie(this, "sin_city.mp4");
  movies[1] = new Movie(this, "blue_velvet.mp4");
  movies[2] = new Movie(this, "finale.mp4");

 }

void draw() { 
  background(0);
  set(0,0,movies[idx] ); 
  //image(films[0],0,0);
  //image(films[1],0,0);
  //image(films[2],0,0);
} 

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

void keyPressed() {


 if (key == '\n' ) {
    saved = typing;
    // A String can be cleared by setting it equal to ""
    typing = ""; 
  } else {
    // Otherwise, concatenate the String
    // Each character typed by the user is added to the end of the String variable.
    typing = typing + key; 
  }

 int k = keyCode, n = getMovieIndex(k) ;

  if (n >= 0){ //& n!= idx) {
    movies[idx].pause();
    movies[idx = n].loop();
  }
}


int getMovieIndex(int k) {
  if ( saved.equals("apple")){
  return 0;
  }else if(saved.equals("blue")){
  return 1;
  }else if(saved.equals("red")){
  return 2;
  }else{
  return -1;
  }
}


and this is the code for triggering the audio clips

import ddf.minim.spi.*; import ddf.minim.signals.*; import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.ugens.*; import ddf.minim.effects.*;

Minim minim;

static final int QTY = 3;
final AudioPlayer[] players = new AudioPlayer[QTY];
int idx;
String typing = "";
String saved = "";

void setup() { 
  size(1440, 900, JAVA2D);
  frameRate(30);
  noSmooth();
  minim = new Minim(this);
  //player = minim.loadFile(“drums.wav”);
  players[0] = minim.loadFile("one.mp3");
  players[1] = minim.loadFile("two.mp3");
  players[2] = minim.loadFile("three.mp3");

 }

void draw() { 
  background(0);
  //set(0,0,players[idx] ); 
  //image(films[0],0,0);
  //image(films[1],0,0);
  //image(films[2],0,0);
} 

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

void keyPressed() {


 if (key == '\n' ) {
    saved = typing;
    // A String can be cleared by setting it equal to ""
    typing = ""; 
  } else {
    // Otherwise, concatenate the String
    // Each character typed by the user is added to the end of the String variable.
    typing = typing + key; 
  }

 int k = keyCode, n = getMovieIndex(k) ;

  if (n >= 0){ //& n!= idx) {

    players[idx].pause();  
    players[idx = n].play();

      }
}


int getMovieIndex(int k) {
  if ( saved.equals("apple")){
  return 0;
  }else if(saved.equals("blue")){
  return 1;
  }else if(saved.equals("red")){
  return 2;
  }else{
  return -1;
  }
}

Any kind of help would be GREATLY appreciated :D

Answers

This discussion has been closed.