1
Well, I made the code more readable...
The same is true of a web radio player.
It has functionality however I would like to add a message waiting / wait, when the video/music takes long to load.
Where I should 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();
}
}
}