How do I know the percentage loading MediaPlayer
?
Since the load is delayed, I would like to know the percentage to inform the user.
I am loading on AssynTask
class Play extends AsyncTask<String, Boolean, Boolean> {
@Override
protected void onPreExecute() {
btnPlayPause.setBackgroundResource(R.drawable.carregando);
btnPlayPause.setEnabled(false);
progressDialog.setMessage("Carregando...");
//progressDialog.show();
}
@Override
protected Boolean doInBackground(String... params) {
try {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setDataSource(params[0]);
mPlayer.prepare(); // might take long! (for buffering, etc)
mPlayer.wait;
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
protected void onPostExecute(Boolean result) {
if (progressDialog.isShowing()) {
progressDialog.cancel();
}
if(result == true){
conexao = true;
mPlayer.start();
btnPlayPause.setBackgroundResource(R.drawable.pause);
} else {
conexao = false;
btnPlayPause.setBackgroundResource(R.drawable.play);
}
btnPlayPause.setEnabled(true);
notificacao();
}
}