【问题标题】:Android L SoundPool.load() regressionAndroid L SoundPool.load() 回归
【发布时间】:2014-12-22 00:23:01
【问题描述】:

在 Android L - 最新的开发者预览版 (Nexus 5) 上,SoundPool.load() 方法似乎有一个回归,加载样本 (5 秒,其中样本是在预加载的-L 系统立即使用完全相同的代码。

我尝试了 OGG 或 MP3,结果都一样。尝试了不同的大小,但都低于 100kb。似乎 40kb 或 80kb 没有任何区别,OGG 或 MP3 也是如此。加载总是延迟 5 秒左右。

在 4.3 中循环被破坏后,这似乎是 SoundPool 中的又一次回归。

这个问题很容易重现:

    pool = new SoundPool(6, AudioManager.STREAM_MUSIC, 0);
    // use a listener to start playback after load
    pool.setOnLoadCompleteListener(listener);

    // R.raw.sound1 is either an OGG or MP3 sample under 100kb od size
    int id = pool.load(context, R.raw.sound1, 1);

    // onLoadComplete() method of the listener is called several seconds after the call to laod()

使用 Builders 引入的 API 21 构建 SoundPool 时也是如此:

    AudioAttributes attr = new AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
            .build();

    pool = new SoundPool.Builder().setAudioAttributes(attr).setMaxStreams(6).build();

还有其他人遇到过这种情况吗?有人找到解决方法吗?

非常感谢!

【问题讨论】:

  • 在 Nexus 7 2012 上存在相同问题,最终棒棒糖版本 (LRX21P)
  • Nexus 4 存在同样的问题,设备通过无线方式更新到 Android L。虽然带有 Android L 的 Nexus10 没有这样的问题。
  • 同样的问题 nexus 5..... wtf...¿??¿?¿?¿ with android 5.0.1 official
  • 相同 - Nexus 10,有什么解决方法吗?应用程序过去需要大约 2.5 秒才能加载,现在只需不到 8 秒 :-(

标签: android android-5.0-lollipop soundpool


【解决方案1】:

让你们知道,这是一个已知的错误:

我尝试过多线程...从某种意义上说它工作正常,它不会阻止应用程序!但是您需要知道在加载所有声音之前不能调用 Soundpool.load 方法。即使您在已经加载的声音上调用 load,它也会导致应用程序冻结。我猜 SoundPool 类有某种内部同步。无论如何,您可以使用此方法使您的应用程序正常工作。这是一种可以提供帮助的 sn-p:

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

在你的代码中:

playSound(String str){
    if (!mAllSoundsAreLoaded)
    return;
    // otherwise: do mSoundPool.load(....)
}

【讨论】:

    猜你喜欢
    • 2019-12-09
    • 2020-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 2017-09-26
    • 1970-01-01
    • 2015-07-21
    相关资源
    最近更新 更多