android java mediaplayer Service - how can I know

2019-08-08 00:31发布

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条回答
劫难
2楼-- · 2019-08-08 01:00

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.

查看更多
登录 后发表回答