Audio with soundpool ok - but it drops out
in
Android Processing
•
1 year ago
Hi,
I've got a small audio test working using soundpool. The below code plays a note when hitting the menu button and is the basis for a larger application I've made.
- import android.media.SoundPool;
- import android.content.res.AssetManager;
- import android.media.AudioManager;
- SoundPool soundPool;
- AssetManager assetManager;
- int sound1;
- void setup() {
- soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
- assetManager = this.getAssets();
- try {
- sound1 = soundPool.load(assetManager.openFd("c2.ogg"), 0);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- void draw() {
- }
- void keyPressed() {
- if(keyCode == MENU) {
- soundPool.play(sound1, 1, 1, 0, 0, 1);
- }
- }
- public void onDestroy() {
- super.onDestroy();
- if(soundPool!=null) {
- soundPool.release();
- }
- }
I may be clutching at straws here but do I need to add something to the AndroidManifest.xml to tell it to prioritise my audio? Otherwise could there be something wrong with the code? I suppose Processing converts the code to Android-friendly java and keeps some of the more complex activity/service/audio focus business behind the scenes.. which is great if it works, but this has got me stumped. Frustrating because the problem is quite intermittent and the rest of my little music app is working very well.
I've looked at the Android dev site but haven't found any answers there yet. Any ideas much appreciated.
1