加载的MP3到Sound池的Android [英] Loading MP3s into the Sound Pool in Android
问题描述
我要加载一对夫妇的MP3成音库,但我将只使用这些MP3文件的活动3,是否有可能加载MP3音乐活动中的1?
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 Activity that loads it uses it?
我无法找到的文档的答案。
I can't find the answer in the docs.
推荐答案
您可以随时加载和使用它们无处不在。最好的办法重新使用的Soundpool
对象将扩展应用程序
类,并在那里声明一个私有变量这是你的的Soundpool
。是这样的:
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:
class MyApp extends Application {
private static MyApp singleton;
private static SoundPool mSoundPool;
public onCreate() {
super.onCreate();
singleton = this;
mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); Just an example
}
public static MyApp getInstance() {
return singleton;
}
public SoundPool getSoundPool() {
return mSoundPool;
}
}
现在,你在任何地方code可以运行:
Now, anywhere on you code you can run:
MyApp.getInstance().getSoundPool();
和你将有机会获得全局的Soundpool对象。
and you'll have access to your global SoundPool object.
PS:不要忘记更新清单如果你扩展应用程序类
PS: don't forget to update the Manifest if you extend the Application Class.
这篇关于加载的MP3到Sound池的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!