MediaPlayer no longer working on the emulator since r10?

﹥>﹥吖頭↗ 提交于 2019-12-18 04:40:43

问题


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 ????


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/5259849/mediaplayer-no-longer-working-on-the-emulator-since-r10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!