Reputation: 81
I am trying to create an ar android application. But I'm unable to do so. I tried using SoundPool but the audio file never plays. Could somebody guide me how to use soundpool? I'm a complete beginner.
Upvotes: 0
Views: 803
Reputation: 553
A SoundPool is designed to play small files, usually shorter than 30 seconds. You construct a SoundPool like so:
SoundPool player = new SoundPool(int maxStreams, int streamType, 0);
You load a sound file like so:
int soundID = player.load(Context ctxt,int audioFile, int priority);
where audioFile is R.raw.somesound
(do not include file extension). Note that you want to keep the return value of the .load method, or you won't be able to play the sound.
You play a sound like so:
int streamID = player.play(soundID, float leftVolume, float rightVolume ,int priority, int loop, float rate);
where leftVolume and rightVolume are floats from 0 to 1, not inclusive. You may want to keep the streamID to pause or stop the sound later. Note that you must wait until the sound is loaded, in order to play it (use setOnLoadCompleteListener method)
See the documentation for more info.
Upvotes: 2