I wanted to implement basic media player functionality and was confused between PrepareAsync() and Prepare() method calls. Which one should be used if the audio file is in the raw folder .
The difference between those methods is basically in what thread they're executed.
Prepare
runs in the thread you call it (most frequently UI thread) and thus if it takes long time (buffering video from the Internet and such) it will block your UI thread and a user might get ANR.
PrepareAsync
runs in a background thread and thus UI thread is not blocked as it returns almost immediately. But the player is not prepared so you want to set onPreparedListener
in order to know when the MediaPlayer
is ready to be used.