android - SoundPool not playing sounds -
i made soundmanager class uses soundpool functions in order loop specific sound, can't figure out why isn't playing sound.
public class soundmanager { private soundpool msoundpool; private hashmap<integer, integer> msoundpoolmap; private audiomanager maudiomanager; private context mcontext; public soundmanager() { } public void initsounds(context thecontext) { mcontext = thecontext; msoundpool = new soundpool(4, audiomanager.stream_music, 0); msoundpoolmap = new hashmap<integer, integer>(); maudiomanager = (audiomanager)mcontext.getsystemservice(context.audio_service); } public void addsound(int index, int soundid) { msoundpoolmap.put(index, msoundpool.load(mcontext, soundid, 1)); } public void playsound(int index) { int streamvolume = maudiomanager.getstreamvolume(audiomanager.stream_music); msoundpool.play(msoundpoolmap.get(index), streamvolume, streamvolume, 1, 0, 1f); } public void playloopedsound(int index) { int streamvolume = maudiomanager.getstreamvolume(audiomanager.stream_music); msoundpool.play(msoundpoolmap.get(index), streamvolume, streamvolume, 1, -1, 1f); }
}
this class being called activity via:
private soundmanager msoundmanager; msoundmanager = new soundmanager(); msoundmanager.initsounds(getbasecontext()); msoundmanager.addsound(1, r.raw.sound); msoundmanager.playsound(1);
apparently doesn't work oncreate activity calling when event happen (intents / keypress) seems work
Comments
Post a Comment