Help with soundpool and general audio for android using the emulator
in
Android Processing
•
2 years ago
Hi,
Just trying to put together my first android app. Its all fairly basic at the moment but i'm struggling to get audio working. After much searching I eventually got soundpool running(well its no longer giving me any errors anyway so I think its working) but i'm still not getting any sounds when I run the app on the emulator
So far I have this in the declarations before setup:
final String beep = "beep.aif";
int beepsound;
import android.media.SoundPool;
import android.media.MediaPlayer;
import android.media.AudioManager;
import android.media.AudioFormat;
import android.content.res.AssetManager;
MediaPlayer mediaPlayer;
SoundPool soundPool;
AssetManager assetManager;
This is called during my setup:
void soundsInit() {
soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
mediaPlayer = new MediaPlayer();
assetManager = this.getAssets();
try {
beepsound = soundPool.load(assetManager.openFd(beep), 1);
}
catch (IOException e) {
e.printStackTrace();
}
}
and then i'm trying to play sounds using:
soundPool.play(beepsound, 1, 1, 0, 0, 1);
As i said i'm not getting any errors and I presume the file is being loaded because it's no longer telling me it cant find it(its just in my "data" folder for the project) but its not being played.
Is this because of the emulator or have I missed something?
There is more to the app than just this but none of it is related to the audio other than calling for the filse to be played. Most of the code above has been more or less directly copied and pasted from other examples and i've just changed variables etc. If anyone could help me on this, or has a simple example code of how to get an audio file running it would be a massive help.
Cheers!
1