Android的大号SoundPool.load()回归 [英] Android L SoundPool.load() regression

查看:165
本文介绍了Android的大号SoundPool.load()回归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在机器人L - 最新显影剂preVIEW(Nexus的5),似乎有在SoundPool.load()方法,需要> 5秒加载样本的回归(小于100KB),其中样品被装上preL系统立即用同样的code。

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 samples were loaded on pre-L systems instantly with the very same code.

我试过OGG或MP3,都是具有相同的结果。尝试不同的大小,但都在100KB。似乎40KB或80KB没有任何区别,因此不会OGG或MP3。数据加载中始终围绕5秒的延迟。

I tried OGG or MP3, both with same results. Tried different sizes but all under 100kb. Seems as 40kb or 80kb does not make any difference, so does OGG or MP3. Loading is always around 5s delay.

这似乎又循环陆续回归中的Soundpool已在4.3打破。

This seems as yet another regression in SoundPool after looping has been broken in 4.3.

这个问题很容易重现性:

The issue is easily reproducible with:

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

同样发生使用的建设者构建的Soundpool推出API 21如下:

The same is happening for constructing the SoundPool using the Builders introduced API 21 as follows:

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

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

是其他任何人遇到此?有没有人找到一个解决办法?

Is anyone else experiencing this? Did anyone find a workaround?

非常感谢!

推荐答案

只是让你们知道,这是一个已知的bug:

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

我也试过多线程...它工作确定在一定意义上,它不会阻止应用程序!但是你要知道,你不能调用Soundpool.load方法,所有的声音都加载之前。即使你叫上已经加载了完善的负载,它会导致应用程序冻结。我猜的Soundpool类有某种一些内部同步。不管怎么说,你可以让你的应用程序排序使用这种方法的工作。这是排序的代码片段,可以帮助:

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

和在code:

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

这篇关于Android的大号SoundPool.load()回归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆