19
protected MediaPlayer _mediaPlayer;  

protected void playFromResource(int resId)     
    {     
    if (_mediaPlayer != null)         
        {         
        _mediaPlayer.stop();         
        _mediaPlayer.release();
        }     
    _mediaPlayer = MediaPlayer.create(this, resId);
    _mediaPlayer.start();
    }  

This code used to work fine on both the emulator and on devices. Since some time (I think it is since I updated to ADT r10) it only works on devices. On the emulator there is no sound anymore and the application freezes when it pass on _mediaPlayer.release() (the second time the function is called). I was able to keep the application from crashing by replacing the stop() and release() by reset() but it does not solve the main issue: There is no sound on the emulator.

the log file show me a bunch of these (only on the emulator) just after the call to start()

03-09 19:14:30.716: WARN/AudioTrack(34): obtainBuffer timed out (is the CPU pegged?) 0x1afb8 user=00001e00, server=00000600

Any clues ????

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
Regis St-Gelais
  • 3,156
  • 5
  • 27
  • 40

5 Answers5

22

I had this problem on my MacBook Pro and found that I had to turn off my Bluetooth before launching the emulator.

g_pass
  • 711
  • 7
  • 15
11

I see this problem on mac os as well. In my case it happens when you enable "snapshot" for the emulator.
http://code.google.com/p/android/issues/detail?id=14953
You will have to delete the emulator and make a new one without "snapshot" enabled.

Jan Sindberg
  • 479
  • 6
  • 9
4

Looks like the issue is only on my computer. I just tryed it on another computer and it work fine. I had some issues when I upgraded to r10 of ADT. Maybe there is something wrong in my development setup.

Regis St-Gelais
  • 3,156
  • 5
  • 27
  • 40
  • Looks like it is caused by one of the latest windows update (i'm on Windows XP). I ran Windows update (it installed 5 updates) on the second computer where it was working and it is not working anymore. – Regis St-Gelais Mar 11 '11 at 14:56
  • 3
    After more tests I figured out that the issue on the second computer is related to the emulator snapshot. After some windows updates, one must recreate the emulator snapshot to make it work properly. That fixed the issue on the second computer. For the first computer I still get the issue if I start the emulator from a snapshot (even if a recreated it). It work fine if I start from a new emulator session (without a snapshot) – Regis St-Gelais Mar 18 '11 at 14:04
2

Launching the emulator manually helps in my case.

emulator program can be found inside android-sdk/tools/.

So the final command will be something like:

android-sdk/tools/emulator -avd my_cool_emulator_name

Al Mamun
  • 944
  • 9
  • 27
0

Be sure you read MediaPlayer State Diagram and that you perform all requested actions when you close your MediaPlayer object; if you don't stop, reset and realeas it, next time you try to use it, it will be in an incoherent state so that you cannot start it.

For details: http://developer.android.com/reference/android/media/MediaPlayer.html

MackTheKnife
  • 101
  • 1
  • 6