SoundPool 应用程序加载时间
我使用 SoundPool 将大约 100 个 .mp3 加载到应用程序中。然而,这会将应用程序的负载从 3 秒增加到 12 秒。
我很欣赏 SoundPool 需要加载和加载将声音解码到内存中,但是这个持续时间正常吗?有没有办法在后台加载声音而不影响应用程序加载时间?
public void initSounds()
{
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
soundPoolMap = new HashMap<Integer, Integer>();
Log.i("Initialising Sounds ------ > ",""+soundPool.toString() );
Class raw = R.raw.class;
Field[] fields = raw.getFields();
Context con = GlobalVars.ACTIVITY_1.getApplicationContext();
for (int i = 1; i < 91; i++)
{
try
{
int id = fields[i].getInt(null);
soundPoolMap.put(i, soundPool.load(con, id, 1));
}
catch (IllegalAccessException e)
{
Log.e("REFLECTION", String.format("%s threw IllegalAccessException.", fields[i].getName()));
}
}
}
I have used the SoundPool to load around 100 .mp3s into an application. This, however increases the load of the app from 3 seconds to 12 seconds.
I appreciate the SoundPool needs to load & decode the sounds into memory, but is this duration normal? Is there any way to load the sounds in the background without affecting the application load time ?
public void initSounds()
{
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
soundPoolMap = new HashMap<Integer, Integer>();
Log.i("Initialising Sounds ------ > ",""+soundPool.toString() );
Class raw = R.raw.class;
Field[] fields = raw.getFields();
Context con = GlobalVars.ACTIVITY_1.getApplicationContext();
for (int i = 1; i < 91; i++)
{
try
{
int id = fields[i].getInt(null);
soundPoolMap.put(i, soundPool.load(con, id, 1));
}
catch (IllegalAccessException e)
{
Log.e("REFLECTION", String.format("%s threw IllegalAccessException.", fields[i].getName()));
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您真的很幸运,能够获得 100 个 MP3 文件(而不是事件 OGG)的 12 秒时间。我的答案现在可能不再那么相关了,因为在 2020 年,我正在为 soundpool 中 32 个 OGG 文件的 50 秒加载时间而苦苦挣扎。
You are really lucky to get 12 seconds for 100 MP3 files, not event OGGs. My answer could no longer be so relevant right now as in 2020 I am struggling with a 50 second load time for 32 OGG files in soundpool.
为了使声音池加载更快,您应该使用 WAV
To make sound pool load faster you should use WAV