Minim Sound Library - NullPointerException after 7 calls

edited December 2015 in Library Questions

Minim gives me a NullPointerException after making 7 calls to the player function. I've tried both .mp3 and .wav files but get the same result. Minim will indicate that it cannot find a particular .wav or .mp3 file that does exists in the data folder. I would appreciate any help or idea? Thanks in advance. Ron

// file: Lily5.pde

    import ddf.minim.*;
AudioPlayer player1; // player for sound
AudioPlayer player2; // player for name
Minim minim1; //audio context for sound
Minim minim2; // audio context for name



// List of animals
StringList animalList = new StringList(
      "alligator", "bear", "cat", "dog", "elephant",
      "frog", "goat", "horse", "bluejay",
      "koala", "lion", "monkey", "owl",
      "pig", "raccoon", "squirrel", "turkey", "vulture",
      "whale", "yak", "zebra");

// animal image, sound and name matricies 
PImage[] images = new PImage[animalList.size()];
String[] animalSound = new String[animalList.size()]; 
String[] animalName = new String[animalList.size()];

String aList = "";
String aName = "";
PImage lily;
String imgName;
String sound;
int col;
int key1;
boolean keyHit;

void setup() {
  size(1024, 960);
  textSize(128);
  imageMode(CENTER);



  // Create and load image & sound matricies
  // ---------------------------------------
  int i = 0;
  for (String animal : animalList) {
    imgName = "data/" + animal + ".jpg";
    images[i] = requestImage(imgName);
    //images[i].resize(width,height);
    sound = "data/" + animal + ".wav";
    animalSound[i] = sound;
    aName = "data/say-" + animal + ".wav";
    animalName[i] = aName;
    aList += animal.charAt(0);
    i ++;
  }

  frameRate(10);
  //minim = new Minim(this);

  // Load start image and sound
  // --------------------------
  //showLily();

  noLoop();

}

void draw() {
  if (keyHit) {
    keyHit = false;
    col = color(random(255), random(255),random(255));
    background(col);
    int key1 = aList.indexOf(key);
    if (key1 == -1) {
      background(col);
      fill(#18ED76);
      text(Character.toUpperCase(key), width/2, height/2);
    return; }

    playName(key1);

    showImage(key1);

    playSound(key1);

    char letter = aList.charAt(key1);
    showLetter(letter, animalList.get(key1));
  }
}

void keyPressed(){
  keyHit = true;
  redraw();
}

void playSound(int k) {
  //if(player2.isPlaying()) {
  //  player2.pause();
  //}
  minim1 = new Minim(this);
  println(animalSound[k]);
  player1 = minim1.loadFile(animalSound[k]);
  player1.play();  _**<<-- null pointer exception always occurs at this location**_
}

void playName(int k) {
  //if(player1.isPlaying()) {
  // player1.pause();
  //}
   minim2 = new Minim(this);
   player2 = minim2.loadFile(animalName[k]);
   player2.play();
}

void showLetter(char letter, String animal) {
  col = color(random(255), random(255),random(255));
  fill(col);
  letter = Character.toUpperCase(letter);
  textAlign(LEFT);
  text(letter, 50, 110);
  textAlign(CENTER);
  text(animal, width/2 - (animal.length()/2), height -75);
  textAlign(RIGHT);
  text(letter, width-100, height-50);
}

void showImage(int k) {
 image(images[k], width/2, height/2, 700,600);
}

void showLily() {
  col = color(random(255), random(255),random(255));
  background(col);
  //player=minim.loadFile("data/kookaburra.mp3");
  //player.play();
  imgName = ("data/Lily1.jpg");
  lily = loadImage(imgName);
  image(lily, width/2, height/2);
  fill(255);
  showLetter('L', "Lily");
}

void stop() {
 player1.close();
 player2.close();
 minim1.stop();
 minim2.stop();
 super.stop();
}

Link to previous question on same topic. https://forum.processing.org/two/discussion/13896/minim-nullpointerexception-after-multiple-player-play-executions

Tagged:

Answers

Sign In or Register to comment.