user433825
user433825

Reputation:

SoundPool sounds not changing

I have a soundpool object and several sounds, but once created I can't change the sounds playback in anyway, such as number of loops, volume, stopping, etc.

Declaration code:

public SoundPool sounds;
public HashMap<Integer, Integer> soundmap = new HashMap<Integer, Integer>();
static final public int UFO=3;
static final public int PlayerDeath=3;
static final public int InvaderDeath=2;
static final public int PlayerFire=1;

Sound assignment code:

sounds = new SoundPool(10,AudioManager.STREAM_MUSIC,0);
soundmap.put(PlayerDeath,sounds.load(getContext(), R.raw.explosion, 1));
soundmap.put(InvaderDeath,sounds.load(getContext(), R.raw.invaderkilled, 1));
soundmap.put(PlayerFire,sounds.load(getContext(),R.raw.shoot, 1));
soundmap.put(UFO,sounds.load(getContext(),R.raw.ufo, 1));

Start/stop code:

public void PlayUFOMusic()
{
    sounds.play(soundmap.get(UFO),0.8F,0.8F,1,2000,1);      
}

public void StopUFOMusic()
{
     sounds.stop(soundmap.get(UFO));
}

I know these functions are being called but nothing will cause it change in anyway. I've also tried setLoop, setVolume, pause and unload, none of these worked either.

Any ideas?

Upvotes: 1

Views: 1076

Answers (1)

softarn
softarn

Reputation: 5497

Here is the play() syntax:

public final int  play  (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)

So shouldn't it be:

 sounds.play(soundmap.get(UFO),0.8F,0.8F,1,-1, 1);

to make the sound loop forever?

Edit: Read the question a bit to fast but if you use this play function, does it loop?

Upvotes: 1

Related Questions