I’m trying to work through this book on android programming and one of the examples is how to play sounds using the SoundPool.
However it always gives me the same error in LogCat:
AudioFlinger could not create track, status -12.
I googled the error and for everyone else seems to be derived from trying to play too many sounds. But mine fails on the first attempt to play a sound. I get the same error when using the MediaPlayer. Is there something I haven’t set up properly in the AVD? Audio playback support is on.
I also loaded this onto my phone and it works fine. It only fails in the emulator. Apparently this is due to a bug in the emulator where sounds won’t play if snapshot is enabled.
Created a new AVD and it works, however the sound is badly choppy. Is this normal?
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;
}
}
sorry to see this unanswered for so long. I have been hitting this bug for months both on Windows and Linux, even in virtual machines. Just boot without snapshot, it’s not much slower nowadays.
I usually boot an emulator every few days, but launch an app every few minutes.
There is a way to run an Android VM using Virtual box and connect it via ADB here:
http://dev.blogs.nuxeo.com/2011/10/speeding-up-the-android-emulator.html
thus, speed is much better as it’s x86 virtualized rather than ARM on x86.