开发者

SoundPool application load time

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开发者_JAVA百科 (IllegalAccessException e)
        {
            Log.e("REFLECTION", String.format("%s threw IllegalAccessException.", fields[i].getName()));
        }
    }
}


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.


To make sound pool load faster you should use WAV

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜