import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.content.Context;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.media.AudioManager;
SoundPool soundPool;
HashMap<Object, Object> soundPoolMap;
Activity act;
Context cont;
AssetFileDescriptor afd1;
int s1;
int streamId;
void playSound(int soundID)
{
soundPool.stop(streamId); // kill previous sound - quick hack to void mousePressed triggering twice
streamId = soundPool.play(soundID, 1.0, 1.0, 1, 0, 1f);
}
void setup() {
act = this.getActivity();
cont = act.getApplicationContext();
// load up the files
try {
afd1 = cont.getAssets().openFd("DTMF-0.mp3");
}
catch(IOException e) {
println("error loading files:" + e);
}
// create the soundPool HashMap - apparently this constructor is now depracated?
soundPool = new SoundPool(12, AudioManager.STREAM_MUSIC, 0);
soundPoolMap = new HashMap<Object, Object>(2);
soundPoolMap.put(s1, soundPool.load(afd1, 1));
};
void draw() {
if(keyPressed)
playSound(1);
};
Processing Android sketch that plays MP3 Audio file
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.