suku suku - 1 year ago 141
Android Question

What is the difference between mediaplayer.create() and mediaplayer.prepareAsync()?

I have used the following code:

mp = MediaPlayer.create(this, Uri.parse("file://"+filePath));

This works fine. Then I wanted to play music from a folder

mp.setDataSource(this, Uri.parse("file://"+filePath));
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {

Are there any performance differences between the two method?

Answer Source

Sure, create method inits object in main thread. So code lines below it should wait for create.

On the other hand, prepare asynchronous opens a new thread to init object then notify you to run next operations while main thread run other lines.

Edit: As @CommonWares mentioned in the comment, mp.create() is a convenient method of calling mp.setDataSoucer() + mp.prepare() at the same time

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download