Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 985
Joe C Avatar asked Jan 29 '14 17:01

Joe C


People also ask

Which of the following are possible states of a Media Player object?

From this state diagram, one can see that a MediaPlayer object has the following states: When a MediaPlayer object is just created using new or after reset() is called, it is in the Idle state; and after release() is called, it is in the End state. Between these two states is the life cycle of the MediaPlayer object.

What is the use of Media Player class?

MediaPlayer Class in Android is used to play media files. Those are Audio and Video files. It can also be used to play audio or video streams over the network.

Which of the following method of the Media Player class uses the SurfaceHolder object to display video content?

The Media Player requires a SurfaceHolder object for displaying video content, assigned using the setDisplay() method. The Surface View is a wrapper around the Surface Holder object. Note that we must implement the SurfaceHoler. Callback interface.


1 Answers

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).

like image 72
Dave Avatar answered Sep 30 '22 12:09

Dave