我使用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()));
}
}
}
答案 0 :(得分:0)
您真的很幸运能获得100秒MP3文件的12秒,而不是事件OGG。我的答案现在可能不再那么重要了,因为在2020年,我正在为50个加载时间在声池中加载32个OGG文件而苦苦挣扎。
答案 1 :(得分:-1)
要使声音池加载更快,您应该使用WAV