Is the API of the SoundPool the same in cupcake?
I hope so.
For all the people who need a reliable soundpool, i have made a class
that handles the details with soundpool and is easy to use:
import java.util.HashMap;
import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Vibrator;
import android.util.Log;
public class SoundEffects {
public boolean released=false;
protected Context context;
private SoundPool soundPool;
private int volume;
private HashMap<Integer, Integer> soundPoolMap;
protected SoundEffects(int size, Context context) {
this.context=context;
// keep maxStreams high, ugly hack because pre cupcake android
could
deadlock
// with soundpool
soundPool=new SoundPool(size+20, AudioManager.STREAM_MUSIC, 40);
soundPoolMap = new HashMap<Integer, Integer>();
AudioManager mgr=(AudioManager)context.getSystemService
(Context.AUDIO_SERVICE);
volume=mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
}
/*
public boolean isLoaded() {
soundPool.
}
*/
public void addSound(int resid) {
int soundId=soundPool.load(context, resid, 1);
soundPoolMap.put(resid, soundId);
soundPool.setLoop(soundId, 1);
}
public void addLoopSound(int resid) {
int soundId=soundPool.load(context, resid, 1);
soundPoolMap.put(resid, soundId);
soundPool.setLoop(soundId, -1);
}
public void play(int resid) {
Log.i("SoundEffects", "Playing: "+resid);
int soundId=soundPoolMap.get(resid);
soundPool.setLoop(soundId, 1);
soundPool.play(soundId, volume, volume, 1, 0, 1f);
}
public void playLoop(int resid) {
int soundId=soundPoolMap.get(resid);
soundPool.setLoop(soundId, -1);
soundPool.play(soundId, volume, volume, 1, 0, 1f);;
}
public void stop(int resid) {
//soundPool.stop(resid);
// apperently a bug, workaround
int soundId=soundPoolMap.get(resid);
soundPool.setLoop(soundId, 0);
soundPool.setVolume(soundId, 0f, 0f);
}
public void release() {
released=true;
soundPool.release();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---