Reputation: 1092
I want to load an audio file from internet on MediaPlayer object.
it's my code:
try {
mp.setDataSource(AUDIO URL);
mp.prepare();
mp.start();
}
catch (IOException e) { e.printStackTrace(); }
catch (IllegalArgumentException e) { e.printStackTrace(); }
catch (IllegalStateException e) { e.printStackTrace(); }
but problem is that it's take a lot of time loading audio.
Help me to show a spinning progress dialog before loading audio to after that.
If question is incomplete tell me to complete decreasing.
Upvotes: 1
Views: 6169
Reputation: 132972
you will need to add MediaPlayer.OnPreparedListener to MediaPlayer to show progress dialog when it's preparing as :
ProgressDialog progressDialog = ProgressDialog.show(this,
"Loading Title", "Loading Message");
mp.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if (progressDialog != null && progressDialog.isShowing()){
progressDialog.dismiss();
}
mp.start();
}
});
Upvotes: 3
Reputation: 2550
Not quite a dublicate, but this question has a progress bar while preparing, it would be "quite" easy to modify to progress dialog or something else:
Progress Bar while media player is preparing
Upvotes: 1