2011-12-15 69 views
0

我的應用程序過去需要幾秒鐘才能加載。現在我添加了聲音,需要15秒才能加載。我加載了40個ogg文件,每個文件大小約爲15KB。這是加載代碼:Android - 加載聲音文件需要很長時間

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

有什麼辦法來優化呢?

回答

0

問題不在於將聲音文件加載到SoundPool中的代碼。我禁用了這段代碼,應用程序仍需要15秒才能加載。從項目加載時間刪除文件後減少到幾秒鐘。

相關問題