0

我的应用程序过去需要几秒钟才能加载。现在我添加了声音,加载需要 15 秒。我正在加载 40 个 ogg 文件,每个文件大小约为 15KB。这是加载代码:

public static void Load(Context context, Resources resources) {
    soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
    sounds = new int[5][8];
    audioManager = (AudioManager) context
            .getSystemService(Context.AUDIO_SERVICE);
    actualVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);

    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 8; j++) {
            sounds[i][j] = soundPool.load(context, resources.getIdentifier(
                    "kalimba_c" + Integer.toString(i + 3) + "_"
                            + Integer.toString(j + 1), "raw",
                    ColorLock.PACKAGE_NAME), 1);
        }
    }
}

有没有办法优化这个?

4

1 回答 1

0

问题不在于将声音文件加载到 SoundPool 中的代码。我禁用了此代码,该应用程序仍然需要 15 秒才能加载。从项目中删除文件后,加载时间减少到几秒钟。

于 2011-12-16T15:06:29.010 回答