Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Re : array of audio files - failed

$
0
0
Hello d.dora_92!

Since quarks already spotted the error,
let me give ya some tweaks for your code instead! 

A warning though:
Since I don't have your files, I couldn't test if it really works!
So tell us later whether this version works for ya. 
    import ddf.minim.*;
    
    final static String[] fileNames = {
      "dog", "horse", "frog", "rooster", "cat", "duck", "ear"
    };
    
    final static int numImgs   = fileNames.length;
    final static PImage[] imgs = new PImage[numImgs];
    
    final static int numSongs  = fileNames.length - 1;
    final static AudioPlayer[] songs = new AudioPlayer[numSongs];
    
    final  Minim minim = new Minim(this);
    PImage bg;
    
    void setup() {
      size(1000, 600);
      background(170, 245, 120);
      frameRate(30);
      noLoop();
    
      for ( byte idx = 0; idx != numImgs; 
      imgs[idx] =  loadImage( fileNames[idx++] + ".jpg") );
    
      for ( byte idx = 0; idx != numSongs; 
      songs[idx] = minim.loadFile( fileNames[idx++] + ".wav") );
    
      for (short idx = 0, rows = 100; rows <= 350; rows += 200)
        for (short cols = 100; cols <= 700; cols += 300)
          image(imgs[idx++], cols, rows);
    
      image(imgs[numImgs-1], 475, 25);
    
      bg = get();
    }
    
    void draw() {
      background(bg);
    }
    
    void mousePressed() {
      if (mouseX > 475 && mouseX < 525 
        && mouseY > 25 && mouseY < 75)
        songs[ (int) random(numSongs) ].play();
    
      redraw();
    }
    
    void stop() {
      for ( byte idx = 0; idx != numSongs; songs[idx++].close() );
      minim.stop();
      super.stop();
    }
    


Viewing all articles
Browse latest Browse all 1768

Trending Articles