Android 声音池应用程序加载时间

Android 声音池应用程序加载时间,android,audio,android-asynctask,Android,Audio,Android Asynctask,我使用SoundPool将大约100.mp3加载到一个应用程序中。但是,这会将应用程序的负载从3秒增加到12秒 我理解声音池需要将声音加载并解码到内存中,但这段时间正常吗?有没有办法在不影响应用程序加载时间的情况下在后台加载声音 public void initSounds() { soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); soundPoolMap = new HashMap<Integer, I

我使用SoundPool将大约100.mp3加载到一个应用程序中。但是,这会将应用程序的负载从3秒增加到12秒

我理解声音池需要将声音加载并解码到内存中,但这段时间正常吗?有没有办法在不影响应用程序加载时间的情况下在后台加载声音

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()));
        }
    }
}

你真的很幸运,100个MP3文件能有12秒,而不是事件OGG。我的答案现在已经不再那么重要了,因为在2020年,我在soundpool中的32个OGG文件的加载时间为50秒。

为了加快声音池的加载速度,你应该使用WAV

我从未使用过有这么多内容的声音池。但我看不出有任何理由不能在后台线程中完成所有加载。加载完毕后,请务必告诉主线程。并设置它,使它知道在加载完成之前不要尝试播放任何内容。这是没有办法的。作为解决方案,我建议在应用程序加载后加载声音。我这样做是因为用户正在输入登录详细信息。如果在加载声音之前调用声音,它将遇到空指针异常,但为超快速启动付出的代价很小。