According to the docs, calling start() effective when you play locally available resources for which MediaPlayer does not require fetching data and processing it for playback. For example, playing audio resources from the source folder.
If you are trying to play a resource from a remote source, it is best to use it for OnPreparedListener() , as it may include retrieving and decoding media.
So, if you know for sure that your resource is locally available and has a small length, go to Approach 1 . Otherwise, Approach 2 is suitable.
Ideally, I prefer that.
MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setDataSource(getApplicationContext(), myUri); mediaPlayer.setOnPreparedListener(new OnPreparedListener(){ @Override public void onPrepared(MediaPlayer mp) { mp.start(); } }); mediaPlayer.prepareAsync();
It has always been difficult for me to work with MediaPlayer . Therefore, I would advise you to start with the developer documentation . Go through it, understand the state diagram. I am sure that this will help you resolve many issues that you still have to face.
Puru pawar
source share