Well, I've left the code more readable ...
The same is a web radio player.
It has functionality but I would like to add a wait / wait message when the video / music takes to load.
Where should I implement this functionality in the code below?
package carcleo.com.player;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import java.io.IOException;
public class player extends AppCompatActivity {
private MediaPlayer player;
private String URL;
private Button btnPlayPause;
private Boolean conexao = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
URL = "rtsp://cdn-the-2.musicradio.com:80/LiveAudio/Capital";
btnPlayPause = (Button) findViewById(R.id.btnPlayPause);
btnPlayPause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
if (player == null) player = new MediaPlayer();
tocaPausa();
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void createConexao() throws IOException {
String url = "rtsp://cdn-the-2.musicradio.com:80/LiveAudio/Capital"; // your URL here
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(url);
player.prepare(); // might take long! (for buffering, etc)
btnPlayPause.setText("AGUARDE...");
player.start();
btnPlayPause.setText("PAUSAR");
conexao = true;
}
private void tocaPausa() throws IOException {
if (conexao == true) {
if (!player.isPlaying()) {
player.start();
btnPlayPause.setText("PAUSAR");
} else {
player.pause();
btnPlayPause.setText("TOCAR");
}
} else {
createConexao();
}
}
}