gpt4 book ai didi

Android L SoundPool.load() 回归

转载 作者:可可西里 更新时间:2023-11-01 19:08:01 25 4
gpt4 key购买 nike

在 Android L - 最新的开发人员预览版 (Nexus 5) 上,SoundPool.load() 方法似乎出现了回归,该方法需要 >5 秒来加载样本 (<100kb),其中样本是在预加载时加载的-L 系统立即使用完全相同的代码。

我尝试了 OGG 或 MP3,两者的结果相同。尝试了不同的大小,但都在 100kb 以下。似乎 40kb 或 80kb 没有任何区别,OGG 或 MP3 也一样。加载始终延迟 5 秒左右。

这似乎是 SoundPool 在 4.3 中循环中断后的又一次回归。

这个问题很容易重现:

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

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

非常感谢!

最佳答案

请大家知道,这是一个已知错误:

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

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

关于Android L SoundPool.load() 回归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26577132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com