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

array of audio files - failed

$
0
0
Hi! 

I am trying to create an array of 6 audio files, in order to use them random, when mouse is clicked on an image. Here is code:  

import ddf.minim.*;

Minim minim;

AudioPlayer song1;
AudioPlayer song2;
AudioPlayer song3;
AudioPlayer song4;
AudioPlayer song5;
AudioPlayer song6;
AudioPlayer[] test;

PImage img1;
PImage img2;
PImage img3;
PImage img4;
PImage img5;
PImage img6;
PImage img7;

void setup() {
size(1000,600);
background(169, 244, 120);
minim = new Minim(this);

img1 = loadImage("dog.jpg");
img2 = loadImage("horse.jpg");
img3 = loadImage("frog.jpg");
img4 = loadImage("rooster.jpg");
img5 = loadImage("cat.jpg");
img6 = loadImage("duck.jpg");
img7 = loadImage("ear.jpg");

test = new AudioPlayer[6];
test[0] = Minim.loadFile("dog.wav");
test[1] = Minim.loadFile("horse.wav");
test[2] = Minim.loadFile("frog.wav");
test[3] = Minim.loadFile("rooster.wav");
test[4] = Minim.loadFile("cat.wav");
test[5] = Minim.loadFile("duck.wav");

}

void draw() {
image(img1, 100, 100);
image(img2, 400, 100);
image(img3, 700, 100);
image(img4, 100, 350);
image(img5, 400, 350);
image(img6, 700, 350);
image(img7, 475, 25);

}

void mousePressed(){
if (mouseX > 475 &&
mouseX < 525 &&
mouseY > 25 &&
mouseY < 75) {
int index = int( random(0,5) );
test[index].trigger();
}
}

void stop()
{
song1.close();
minim.stop();

super.stop();
}

As you see, it is a little game, that (so far) when the player clicks on the "ear" image, should hear one random sound of six animals. From all the sites I read to help me understand how to write it, I concluded that this is the best way, although I am always getting an error message saying: "cannot make a static reference to the non-static method loadFile(String) from the type Minim."  I knew that the array was wrong, so i named it "test". Any advice? I've run out of references..! :(


Viewing all articles
Browse latest Browse all 1768

Trending Articles