views:

40

answers:

1

Hi, 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?

A: 

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?

softarn
Ah, sorry, it was -1 originally, but I changed to 2000, to see if having it loop forever was the problem. It does loop, that's not problem though.
raybritton
So the problem is that you cant change the sounds DURING playback? If thats the case, you don't event keep a reference to the streamID that is returned from the play() function. That's the id that you run setLoop() and other methods on. If this doesn't help you, please explain your problem better.
softarn
Ah thank you, I thought the id returned by load was used to control it, with hindsight that it obviously wouldn't work.
raybritton
Thats the soundID, it is just needed in the play function. Don't forget to mark this answer as a correct answer and good luck with the UFOs!
softarn
Thank you so much.
raybritton