Cuando mi url no está funcionando lo que necesito para ajustar un oyente de error que establece el estado fuera de línea en TextView. No sé cómo ajustar esto exactamente. O ¿qué medios de retorno falsas? Cualquier ayuda será agradecido. Aquí está mi reproductor de medios:
lv_tracks.setOnItemClickListener (nueva AdapterView.OnItemClickListener () {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (isNetworkAvailable()) {
mSelectedTrackTitle.setText(stations[position]);
// mSelectedTrackImage.setImageResource(images[position]);
nowplaying.setText("Now Playing");
mPlayerControl.setImageResource(R.drawable.ic_pause_circle_filled);
Resources res = getResources();
String[] links = res.getStringArray(R.array.links);
String url = links[position];
// Toast.makeText(MainActivity.this,url,Toast.LENGTH_SHORT).show();
if (mMediaPlayer.isPlaying()) {
Log.d("abc", "playing and now going to reset : " + url);
try {
mMediaPlayer.pause();
mMediaPlayer.stop();
mMediaPlayer.release();
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(url);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
nowplaying.setText("Offline");
Toast.makeText(MainActivity.this,"SERVER IS DOWN",Toast.LENGTH_SHORT).show();
//mMediaPlayer.release();
e.printStackTrace();
}
} else {
try {
Log.d("abc", "in else part :" + url);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(url);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
nowplaying.setText("Offline");
Toast.makeText(MainActivity.this,"SERVER IS DOWN",Toast.LENGTH_SHORT).show();
//mMediaPlayer.release();
e.printStackTrace();
}
return;
}
} else {
Toast.makeText(MainActivity.this, "No Internet Connection", Toast.LENGTH_SHORT).show();
}
}
});
Logcat (lo primero, cuando selecciono):
10-12 17: 07: 54.426 20.080 a 20.091 / indusradio.pk W / MediaPlayer-JNI: MediaPlayer finalizó sin ser liberado 10-12 17: 07: 54.426 20.080 a 20.091 / indusradio.pk I / MediaPlayerNative: Pid: 20080 MediaPlayer destructor 10-12 17: 08: 29.478 20.080 hasta 20.096 / indusradio.pk D / MediaPlayerNative: Mensaje: MEDIA_ERROR (100), ext1 = MEDIA_ERROR_UNKNOWN (1), ext2 = 0x80000000 10-12 17: 08: 29.480 20.080 hasta 20.096 / indusradio. pk E / MediaPlayerNative: error (1, -2147483648) 10-12 17: 08: 29.480 20.080 a 20.096 / indusradio.pk D / MediaPlayerNative: [notificará]: [1204] devolución de llamada aplicación listenerNotNull = 1, envío = 0 10-12 17: 08: 29.487 20.080 a 20.080 / indusradio.pk D / HwRTBlurUtils: estilo borroso cheque por HwToast-pan tostado, themeResId: 0x7f0900b4, el contexto: com.example.maham.indusradio.MainActivity@77db462, Nhwext: 6, consiguen la falta de definición: desactivado con, android.graphics.drawable.NinePatchDrawable@c363c7 10-12 17:08:29.505 20.080-20.080 / indusradio.pk W / System.err: java.io.IOException: Preparar fallado .: estado = 0x1 10-12 17: 08: 29.506 20.080-20.080 / indusradio.pk W / System.err: al androide .media.MediaPlayer._prepare (nativo Método) 10-12 17: 08: 29.507 20.080 a 20.080 / indusradio.pk W / System.err: en android.media.MediaPlayer.prepare (MediaPlayer.java:1313) 10-12 17 : 08: 29.507 20.080-20.080 / indusradio.pk W / System.err: en com.example.maham.indusradio.MainActivity $ 3.onItemClick (MainActivity.java:174)indusradio.MainActivity $ 3.onItemClick (MainActivity.java:174)indusradio.MainActivity $ 3.onItemClick (MainActivity.java:174)
A veces se bloquea y se tomó el tiempo por unos 20seg para mostrar el estado fuera de línea.
Puede ajustar texto en una captura como
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setDataSource(url);
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer.start();
}
});
mMediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean
onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
mMediaPlayer.prepareAsync();
} catch (IOException e) {
nowplaying.setText("OFFLINE")
e.printStackTrace();
}