Loading Mp3s Into The Sound Pool In Android
I want to load a couple of MP3s into the sound pool, but I will only be using these MP3s on Activity 3, is it possible to load the MP3s in Activity 1? Or is this limited to the Ac
Solution 1:
You can load them anytime and use them everywhere. The best thing to re-use the SoundPool
object would be to extend the Application
class and declare a private variable in there that is your SoundPool
. Something like:
classMyAppextendsApplication {
privatestaticMyApp singleton;
privatestaticSoundPool mSoundPool;
publiconCreate() {
super.onCreate();
singleton = this;
mSoundPool = newSoundPool(1, AudioManager.STREAM_MUSIC, 0); Just an example
}
publicstaticMyAppgetInstance() {
return singleton;
}
publicSoundPoolgetSoundPool() {
return mSoundPool;
}
}
Now, anywhere on you code you can run:
MyApp.getInstance().getSoundPool();
and you'll have access to your global SoundPool object.
PS: don't forget to update the Manifest if you extend the Application Class.
Post a Comment for "Loading Mp3s Into The Sound Pool In Android"