2012-02-23 55 views
1

播放声音我想通过这本书在Android编程和的例子之一是如何发挥使用的Soundpool声音工作。不能在AVD

但是它总是给我的logcat同样的错误:

AudioFlinger could not create track, status -12. 

我一派错误和其他人似乎是从尝试扮演了太多的声音的。但是,我的第一次尝试播放声音失败了。使用MediaPlayer时出现相同的错误。我有没有在AVD中正确设置的东西?音频播放支持已启用。

我也装这个到我的手机,它工作正常。它只在模拟器中失败。显然,其中如果未启用快照的声音不会玩,这是由于在模拟器中的错误。

创建一个新的AVD和它的作品,但声音非常不稳定。这是正常的吗?

public class SoundPoolTest extends Activity implements OnTouchListener { 
    SoundPool soundPool; 
    int explosionId = -1; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     TextView textView = new TextView(this); 
     textView.setOnTouchListener(this); 
     setContentView(textView); 
     setVolumeControlStream(AudioManager.STREAM_MUSIC); 
     soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0); 
     try { 
      AssetManager assetManager = getAssets(); 
      AssetFileDescriptor descriptor = assetManager 
        .openFd("explosion.ogg"); 
      explosionId = soundPool.load(descriptor, 1); 
     } catch (IOException e) { 
      textView.setText("Couldn't load sound effect from asset, " 
        + e.getMessage()); 
     } 
    } 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     if (event.getAction() == MotionEvent.ACTION_UP) { 
      if (explosionId != -1) { 
       soundPool.play(explosionId, 1, 1, 0, 0, 1); 
      } 
     } 
     return true; 
    } 
} 

回答

1

对不起,看到这么长时间没有答案。在Windows和Linux上,我一直在使用这个bug几个月,甚至在虚拟机上。无需快照即可启动,现在速度并不慢。 我通常启动模拟器每隔几天,但启动应用每隔几分钟。 有使用虚拟框运行的是Android虚拟机,它通过ADB在此连接方式: http://dev.blogs.nuxeo.com/2011/10/speeding-up-the-android-emulator.html 因此,速度要好得多,因为它是虚拟化的x86,而不是ARM在x86。