MediaPlayer no longer working on the emulator since r10?
protected MediaPlayer _mediaPlayer;
protected void playFromResource(int resId)
{
if (_mediaPlayer != null)
{ 开发者_StackOverflow中文版
_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 ????
I had this problem on my MacBook Pro and found that I had to turn off my Bluetooth before launching the emulator.
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.
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.
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
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
精彩评论