audio for Android
in
Android Processing
•
1 year ago
I am a newbie so please bear with me. I am teaching an introduction to programming with a grade 9/10 high school class using Processing and so far things are going swimmingly. In particular, the videos that Hamoid made on funprogramming.org have been a fantastic resource.
So we have run into a wall now with getting audio to work on Android. Only too late did I learn that the Minim library doesn't work in Android. I found a couple of references to other ways that people managed to get audio to work in Android but they were way beyond me and I am hoping someone could walk me through the simplest way to get sounds to play.
The project that I am doing to model images and sound is one that I did for my 1 year old. He taps on the screen and it shows an image of a randomly selected member of the family and plays a little audio clip of my 3 year old saying that person's name. On the desktop, it works fine but in Android, there is no audio library.
Here's the program. If someone could suggest a simple way to modify it so I can get it onto my phone, I would be most grateful. I am hoping that my students can create something similar by the end of the semester. (Any other suggestions are welcome as well, of course. Remembering that we are all beginners with this. I find the best way to learn something myself is to put myself in a situation where I have to teach it to someone else...)
import ddf.minim.*;
PImage mommy;
PImage daddy;
PImage joshua;
PImage gabriel;
PImage nana;
PImage papa;
PImage charlotte;
PImage aenea;
PImage shun;
PImage david;
PImage yeye;
PImage ama;
PImage sam;
PImage joe;
Minim minim;
AudioSample mommy_a;
AudioSample daddy_a;
AudioSample gabriel_a;
AudioSample joshua_a;
AudioSample joe_a;
AudioSample charlotte_a;
AudioSample sam_a;
AudioSample aenea_a;
AudioSample nana_a;
AudioSample papa_a;
AudioSample ama_a;
AudioSample yeye_a;
AudioSample shun_a;
AudioSample david_a;
void setup() {
size(480, 800);
background(0);
mommy = loadImage("mommy.jpg");
daddy = loadImage("daddy.jpg");
joshua = loadImage("joshua.jpg");
gabriel = loadImage("gabriel.jpg");
nana = loadImage("nana.jpg");
papa = loadImage("papa.jpg");
charlotte = loadImage("charlotte.jpg");
aenea = loadImage("aenea.jpg");
shun = loadImage("shun.jpg");
david = loadImage("david.jpg");
yeye = loadImage("yeye.jpg");
ama = loadImage("ama.jpg");
sam = loadImage("sam.jpg");
joe = loadImage("joe.jpg");
minim = new Minim(this);
mommy_a = minim.loadSample("mommy.mp3", 2048);
daddy_a = minim.loadSample("daddy.mp3", 2048);
gabriel_a = minim.loadSample("gabriel.mp3", 2048);
joshua_a = minim.loadSample("joshua.mp3", 2048);
aenea_a = minim.loadSample("aenea.mp3", 2048);
ama_a = minim.loadSample("ama.mp3", 2048);
charlotte_a = minim.loadSample("charlotte.mp3", 2048);
david_a = minim.loadSample("david.mp3", 2048);
joe_a = minim.loadSample("joe.mp3", 2048);
nana_a = minim.loadSample("nana.mp3", 2048);
papa_a = minim.loadSample("papa.mp3", 2048);
sam_a = minim.loadSample ("sam.mp3", 2048);
shun_a = minim.loadSample("shun.mp3", 2048);
yeye_a = minim.loadSample("yeye.mp3", 2048);
}
void draw() {
}
void mousePressed() {
background(0);
stroke(255);
fill(255);
String[] family_members = {
"mommy", "daddy", "Gabriel", "Joshua", "tio Joe", "tia Charlotte", "Sam", "Aenea", "Nana", "Papa", "Ama", "Yeye", "tio Shun", "tio David"
};
int n = int(random(14));
textSize(20);
// text(family_members[n], 100, 100);
if (n == 0) {
image(mommy, 0, 0);
text("mommy", 325, 50);
mommy_a.trigger();
}
else if (n == 1) {
image(daddy, 0, 0);
fill(0);
text("daddy", 325, 50);
daddy_a.trigger();
}
else if (n == 2) {
image(gabriel, 0, 0);
fill(0);
text("Gabriel", 325, 50);
gabriel_a.trigger();
}
else if (n == 3) {
image(joshua, 0, 0);
fill(0);
text("Joshua", 325, 50);
joshua_a.trigger();
}
else if (n==4) {
image(joe, 0, 0);
text("tio Joe", 325, 50);
joe_a.trigger();
}
else if (n==5) {
image(charlotte, 0, 0);
text("tia Charlotte", 325, 50);
charlotte_a.trigger();
}
else if (n==6) {
image(sam, 0, 0);
text("Sam", 325, 50);
sam_a.trigger();
}
else if (n==7) {
image(aenea, 0, 0);
text("Aenea", 325, 50);
aenea_a.trigger();
}
else if (n==8) {
image(nana, 0, 0);
text("Nana", 325, 50);
nana_a.trigger();
}
else if (n==9) {
image(papa, 0, 00);
fill(0);
text("Papa", 325, 50);
papa_a.trigger();
}
else if (n==10) {
image(ama, 0, 0);
text("Ama", 325, 50);
ama_a.trigger();
}
else if (n==11) {
image(yeye, 0, 0);
text("Yeye", 325, 50);
yeye_a.trigger();
}
else if (n==12) {
image(shun, 0, 0);
text("tio Shun", 325, 50);
shun_a.trigger();
}
else if (n==13) {
image(david, 0, 0);
fill(0);
text("tio David", 325, 50);
david_a.trigger();
}
}
void stop() {
mommy_a.close();
daddy_a.close();
gabriel_a.close();
joshua_a.close();
joe_a.close();
charlotte_a.close();
sam_a.close();
aenea_a.close();
nana_a.close();
papa_a.close();
ama_a.close();
yeye_a.close();
shun_a.close();
david_a.close();
minim.stop();
super.stop();
}
1