简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM