I have looked at various different websites looking for a solution for this problem in my code. It is a basic audio player with 3 buttons: play, pause and stop. Play and pause w
I fixed this problem by `mediaPlayer.prepare(); My problem is about live radio streaming and I achieve this problem like below code:
if (!radioIsOpen) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer
.setDataSource(URL);
mediaPlayer.prepare();
} catch (Exception e) {
}
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
}
});
Toast.makeText(getBaseContext(), "Radio is opening...", 2).show();
} else {
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
Toast.makeText(getBaseContext(), "Radio is closing...", 2).show();
}
}