问题描述
我使用MediaPlayer
控件提供了绑定服务,该控件可以加载和播放音频.但是碰巧的是,有时候mediaPlayer.prepare();
的速度不够快,并且并不总是准备播放.
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.
那么我该如何制作类似myService.prepare()
这样的方法,在这里我可以要求MediaPlayer准备并等待它?
So how can I make such method , something like myService.prepare()
where I can ask for MediaPlayer to prepare and wait for it?
推荐答案
您可以等待MediaPlayer触发OnPrepared事件.
You may wait for the OnPrepared event to be triggered by the MediaPlayer.
http://developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener.html
prepare()仅阻止文件,因此,如果您使用其他工具,则可能是原因.
Edit : prepare() is blocking only for files, so if you're working with something else, that might be the cause.
这篇关于android java mediaplayer服务-如何知道mediaPlayer是否已准备好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!