suku suku - 2 months ago 18x
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?


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