Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not get any hear any audio from Android SDK emulator launched from eclipse

I am starting to develop for Android, and I am using Eclipse with the Android plugin and Android SDK.

No matter what I do, I can not get the emulator to make any sound.

I have tried turning on audio in the virtual device setup.

I have also tried various command lines in the run configuration such as:

  • -audio oss ==== this gets a error message that there is no oss backend defined.
  • -useaudio === comes up as not a valid option
  • -audion -winaudio === starts w/o error but still no sound

If I open my windows7 audio controller on my laptop, I see that the android virtual machine gets its own volume slider, but nothing sounds when I move or click on that audio slider. (The other volume sliders produce the normal beep sound.)

I've been searching for "Android emulator no sound" for hours but no luck.

Any ideas?

like image 701
Paul Gorbas Avatar asked Nov 05 '22 03:11

Paul Gorbas


1 Answers

The issue was not with the emulator not making sound ( as verified by the fact it would not work on my device either ), but a unaccounted problem with the SoundPool class.

I looked in the logcat and found references like "sample 1 not ready". Researching this I finally found a obscure thread in which it was mentioned that it takes some time before sound pool is ready to be used ( and therefore all sounds should be loaded well before they are used ).

I modified my playSound method to monitor the return value of the soundPool.play(...) method call. It returns the id of the running sound stream, or 0 if it failed ( i.e. "sample 1 not ready" ).

What I did was to put it into a loop, and when the return value of the soundPool.play(...) method call was 0, I had the thread sleep for 1 millisecond, then try again. With this method in place, I now always get a sound.

As a side note I have also been running tutorials with my SDK set up for Android 2.2 instead of Android 2.3.1, because Android 2.2 is what is installed on my device, a Sprint LG optimus S LS670.

I have ran my modified code on both a Android 2.2 and a Android 2.3.1 Virtual device.

When I run the code on the older Android 2.2 VD, it typically took about 10 to 15 loops ( so a 10 to 15 ms delay ) before the sounspool was ready to play the sound.

When I ran the same code on a Android 2.3.1 VD, the delay was MUCH worse, taking around a 350 ms delay before it would play - yes almost 35 times slower!

When I ran the same code deplyed to my device running Android 2.2, the time delap was about identical to running it on the emulator.

like image 102
Paul Gorbas Avatar answered Nov 12 '22 23:11

Paul Gorbas