Should MediaPlayer.start() also be a new thread?

牧云@^-^@ 提交于 2019-12-07 00:44:06

问题


The tutorial here explains that a service actually uses the main thread. So it uses prepareAsync to avoid blocking UIS: http://developer.android.com/guide/topics/media/mediaplayer.html#asyncprepare

I was wondering where the async callback onPrepared runs. In the example onPrepared calls start of MediaPlayer. Is start also a CPU-intensive method? If it runs in the same thread, it also blocks.


回答1:


MediaPlayer.start() is not an intensive operation in the least. The MediaPlayer uses its own native thread to perform tasks, but a call to the synchronous prepare method can take too long for the UI thread, particularly if it is remote media you are trying to play. In that case it has to wait for one or more network requests, data to buffer, etc. The onPrepared callback will happen on the main thread if that is where you called prepareAsync (or whatever thread you called it from, to be more precise).



来源:https://stackoverflow.com/questions/21438583/should-mediaplayer-start-also-be-a-new-thread

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