so I've had an issue I can't quite get my head around. I've been using a static class to hold hold my SoundPool.
e.g.
public class Sound
{
private static SoundPool sounds;
private static int charged;
public static void loadSound(Context context)
{
sounds = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
charged = sounds.load(context, R.raw.charged, 1);
}
public static void playCharged()
{
sounds.play(charged, 1, 1, 1, 0, 1);
}
Then in the onCreate method of my main Activity ( which extends BaseGameActivity ) I do the following:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
Sound.loadSound(this);
So to play the sound I would usually just go Sound.playCharged() from my Game object that is an attribute of my main activity. Before, this all worked great. I'm not sure when it stopped working but, I can only assume once I started making major changes. I supported the Google Play services then put my Game object in another activity.
None of the sounds play. However, I found that sounds do play if call the method to play them within a constructor to my game object or other constructors. My assumption is that something is happening once I've initialised everything, as if something is being lost.
Alright so I eventually managed to solve the problem by not releasing the sounds in the onStop method of my main activity, but the new activity instead that I had created. As the onStop method would be called before starting the 2nd activity messing up with the sounds.