I have my main Activity class, a Renderer class and my custom soundPool class (called soundMan) and I can create and access SoundPool(I.E. soundMan) objects within my Activity class without too many problems.
However, this isn't much good to me, I create all of my objects from resources within my Renderer class (GLSurfaceView.Renderer) which is running on a separate thread.
So, when I attempt to create a new soundPool (soundMan) object from my renderer class, I get the error "can't create handler inside thread that has not called looper.prepare()"
I'm sure there must be a way around this, but I can't work it out. Any help would be appreciated.
Code and examples follow
My Custom soundPool class
public class soundMan extends Activity {
//Simple soundPool class
private SoundPool soundPool;
private int soundID;
soundMan(Context myContext){
soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
soundID = soundPool.load(myContext, R.raw.matches, 1);
}
public void PlaySound(){
soundPool.play(soundID, 0.9f, 0.9f, 1, 0, 0);
}
}
I can create and use an object within my Activity class like so (in onCreate):
soundMan soundPlay = new soundMan(this); //Create object
soundPlay.PlaySound(); //Play the sound
However, I want to be able to do the same as the above but from my rendering thread
I know I can set my soundMan object in my Activity class to static and use it like this:
MainActivity.soundPlay.PlaySound();
But this is obviously not a good way to achieve what I'm after.
Again, examples (with code) would be appreciated.