play mp3 files from an array using minim?

edited November 2015 in Library Questions

Hi im new to using processing/java , just wondering if anyone can help me , i am using minim , and it would love any help/code on how to play an mp3 file from an array. Any help would be appreciated thanks.

Answers

  • dms91, I am doing a similar thing with the following code:

    // 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 + ".mp3";
    animalSound[i] = sound;
    aName = "data/say-" + animal + ".mp3";
    animalName[i] = aName;
    aList += animal.charAt(0);
    i ++;
    

    }

    and playing the sounds after a key press with this code:

    void keyPressed(){
    if (player.isPlaying()){player.pause();}
    
    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));
    }
    
    playName(key1);
    
    showImage(key1);
    
    playSound(key1);
    
    char letter = aList.charAt(key1);
    showLetter(letter, animalList.get(key1));
    }
    
    void playSound(int k) {
    player = minim.loadFile(animalSound[k]);
    player.play();
    }
    
    void playName(int k) {
    player = minim.loadFile(animalName[k]);
    player.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) {
    mage(images[k], width/2, height/2, 700,600);
    }
    

    The image and sound files are in the data folder. The trouble I have with Minim is that if I press keys too quickly the player quits with a null exception.

    Hope this helps.

Sign In or Register to comment.