android java mediaplayer Service - how can I know if mediaPlayer is prepared?

北城余情 提交于 2019-12-24 10:36:27

问题


I made a binded service with MediaPlayer controls which loads and play back audio. But as it happens, sometimes mediaPlayer.prepare(); is not fast enough and it's not always prepared to playback.

So how can I make such method , something like myService.prepare() where I can ask for MediaPlayer to prepare and wait for it?


回答1:


You may wait for the OnPrepared event to be triggered by the MediaPlayer.

http://developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener.html

Edit : prepare() is blocking only for files, so if you're working with something else, that might be the cause.



来源:https://stackoverflow.com/questions/18058073/android-java-mediaplayer-service-how-can-i-know-if-mediaplayer-is-prepared

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