A couple of months ago I made the following post, about how to get sound to play.
https://forum.processing.org/two/discussion/comment/53262
@akenaton was extremely helpful, and helped me get sound to play on my phone. Now I'm ready to take the program to the next level. Eventually I want to make an app to help me learn Cantonese. Right now I'm just trying to make a program that will play 6 different sound files, depending on what button is pressed. Each file is a mp3 and is only one word, so its about 1 second long.
the code below runs fine in java mode:
Button[] b;
import ddf.minim.*;
Minim minim;
void setup() {
// size(1080,1920);//phone res
size(360, 640);// 1/3 of phone res
minim = new Minim(this);
rectMode(RADIUS);
b= new Button[6];
b[0] = new Button(width/6, height-width/6, "sin1.mp3");
b[1] = new Button(3*width/6, height-width/6, "sin2.mp3");
b[2] = new Button(5*width/6, height-width/6, "sin3.mp3");
b[3] = new Button(width/6, height-3*width/6, "sin4.mp3");
b[4] = new Button(3*width/6, height-3*width/6, "sin5.mp3");
b[5] = new Button(5*width/6, height-3*width/6, "sin6.mp3");
//there are 6, 1 second, mp3 files in the folder with the project.
}
void draw() {
background(255);
for (int n = 0; n < 6; n++) {
b[n].update();
}
}
//---------------------------------------------------------
//---------------------------------------------------------
//---------------------------------------------------------
class Button {
float x, y, r;
color myColor;
boolean initialPress;
String mp3;
AudioPlayer player;
Button( float myX, float myY, String myMp3) {
x=myX;
y=myY;
r=width/7;
myColor=color(200, 200, 10);
initialPress=true;
mp3=myMp3;
}
void update() {
fill(myColor);
rect(x, y, r, r);
if (mousePressed && over() && initialPress ) {//when the button is pressed (initially) , this code runs
initialPress=false;
player = minim.loadFile(mp3);
player.play();
} else if ( !mousePressed || !over()) {//when the button is NOT being pressed, this code runs
initialPress=true;
}
}
boolean over() {
float d = max(abs(x-mouseX), abs(y-mouseY)); // this is a square
return d <= r ;
}
}
</code>
I want this to run on my phone. However I learned before that Minim doesn't seem to work in android mode, and I have to use android.media.MediaPlayer instead. I'm not really sure how to even begin doing this. I tried some things before, but when I had multiple sound files in a folder the android media player would just play all files one by one. Therefor I don't even what to show you may attempt to get the android media player to work, because I know I did it all wrong.
I want to get the above code to run on my phone. PLEASE HELP