I use this standard SoundManager. It works fine on all my devices, but only now on the market, and then I get these errors.
Here is the code:
public class SoundManager { private static SoundManager _instance; private static SoundPool mSoundPool; private static HashMap<Integer, Integer> mSoundPoolMap; private static AudioManager mAudioManager; private static Context mContext; private SoundManager(){ } static synchronized public SoundManager getInstance(){ if (_instance == null) _instance = new SoundManager(); return _instance; } public static 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 static void addSound(int Index,int SoundID){ mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1)); } public static void loadSounds(){ mSoundPoolMap.put(1, mSoundPool.load(mContext, R.raw.kick1, 1)); mSoundPoolMap.put(2, mSoundPool.load(mContext, R.raw.kick2, 1)); mSoundPoolMap.put(3, mSoundPool.load(mContext, R.raw.kick3, 1)); } public static void playSound(int index, float volume){ **line 87:** float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); mSoundPool.play(mSoundPoolMap.get(index), streamVolume*volume, streamVolume*volume, 1, 0, 1); } public static void stopSound(int index){ mSoundPool.stop(mSoundPoolMap.get(index)); } public static void cleanup(){ **line 107:** mSoundPool.release(); mSoundPool = null; mSoundPoolMap.clear(); mAudioManager.unloadSoundEffects(); _instance = null; } }
This is a cleanup call that is in initial activity:
//REMOVE SOUND MEMORY ALLOCATION @Override public void onDestroy() { super.onDestroy(); SoundManager.cleanup(); }
Does anyone know what can cause these rare rare errors and how to prevent them? This happens in all of my applications that use this SoundManager ... Even a little spec can help.
Lumis source share