Android L SoundPool.load() regression

后端 未结 1 1237
走了就别回头了
走了就别回头了 2021-02-01 23:56

On Android L - the latest developer preview (Nexus 5), there seems to be a regression in the SoundPool.load() method which takes >5 seconds to load a sample (<100kb), where s

相关标签:
1条回答
  • 2021-02-02 00:41

    Just so you guys know, this is a known bug:

    • https://code.google.com/p/android-developer-preview/issues/detail?id=1812
    • https://code.google.com/p/android/issues/detail?id=81187

    I have tried multi-threading... It works ok in a sense that it doesn't block the app! But you need to know that you can't call Soundpool.load method before all of your sounds are loaded. Even if you call load on a sound that has already been loaded, it causes the app to freeze. I guess the SoundPool class has some sort of internal synchronization of some sort. Anyways, you can make your app sort of work using this method. This is sort of an snippet that can help:

     private class loadSFXasync extends AsyncTask<String, Integer, Long> {
         protected Long doInBackground(String... str) {
             int count = str.length();
             long totalSize = 0;
             for (int i = 0; i < count; i++) {
                 mSoundPool.load(str,1);
                 publishProgress((int) ((i / (float) count) * 100));
             }
             return totalSize;
         }
    
         protected void onProgressUpdate(Integer... progress) {
             setProgressPercent(progress[0]);
         }
    
         protected void onPostExecute(Long result) {
             mAllSoundsAreLoaded=true;
         }
     }
    

    and in your code:

    playSound(String str){
        if (!mAllSoundsAreLoaded)
        return;
        // otherwise: do mSoundPool.load(....)
    }
    
    0 讨论(0)
提交回复
热议问题