I am programming an audio streming app, everything works, the problem is that if one of the url is offline, it stays loading, I would like to set a time limit, for example if in 10 seconds it has not loaded, that stop trying and notify. my code:
private void BotonReproducir() {
if (block == 0) {
if (url != "") {
try {
Toast.makeText(getApplicationContext(), "Bufering...", Toast.LENGTH_LONG).show();
mediaPlayer.setDataSource(url);
fab.setImageResource(R.drawable.ic_media_pause);
mediaPlayer.prepareAsync();
block = 1;
} catch (IOException e1) {
e1.printStackTrace();
}
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer arg0) {
//Inicia reproducción.
mediaPlayer.start();
block = 0;
// Lanzo la notificacion creada en el paso anterior
}
});
} else {
Toast.makeText(getApplicationContext(), "Select a rario", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(getApplicationContext(), "Espere a que cargue la radio anterior", Toast.LENGTH_SHORT).show();
}
}