need to trigger different soundclips based on different string inputs. Using Minim

edited November 2014 in Library Questions

So im using minim. What i need to do is, based on different string inputs, i need different sound clips to play. i had used a code very similar to this to get the same functionality to switch between videos. That worked fine. However when im applying this same logic to music clips its not working properly. whats happening is when i type in the string words****("red" for example)**** the first time it works. However the minute i press any other key on the keyboard the soundclip stops playing. that is just one of the problems. Moreover, if i try to type the same string word again ****("red" for example)****, it does not work at all. Can some one please have a look and help me out! here is the code -

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].close();  
    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;
  }
}

Answers

Sign In or Register to comment.