2 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個贊
您可以使用prepareAsyc()準(zhǔn)備mediaplyer。
試試這個代碼。
//creando botones
Button btnPlay, btnRecargar, btnParar, btnTop, btnNosotros, btnSalir;
MediaPlayer mediaPlayer; // creando clase mediaPlayer para reproducir archivos.
String stream = "http://stream.dancefm.cl:9332"; //variable para la ulr streaming
boolean prepared, started = false; // 2 boleano para el estado del reproductor
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
//instanciando botones creados arriba con los botones fisicos.
btnPlay = (Button) findViewById(R.id.btnPlay);
btnRecargar = (Button) findViewById(R.id.btnRecargar);
btnParar = (Button) findViewById(R.id.btnStop);
btnTop = (Button) findViewById(R.id.btnTop);
btnNosotros = (Button) findViewById(R.id.btnNosotros);
btnSalir = (Button) findViewById(R.id.btnSalir);
WebView myWebbView = (WebView) this.findViewById(R.id.webprincipal); //creando e instanciando webview
myWebbView.loadUrl("https://www.dancefm.cl/noticias/");//Cargando webview
Toast toast = Toast.makeText(getApplicationContext(), "Esperando respuesta del servidor...", Toast.LENGTH_LONG);
toast.show(); //arriba creamos un toast para mostrar un mensaje y aqui abajo lo mostramos.
//Asignando estado a los botones... esto para que mientras este cargando no se utilzen estos botones.
btnPlay.setEnabled(false);
btnParar.setEnabled(false);
btnRecargar.setEnabled(false);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDataSource(stream);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
}

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個贊
您只需將http://xxx.xx.xxx.x/更改為http://xxx.xx.xxx.x/;stream.mp3可以是任何單詞,重要的是放; 在您的 shoucast url 之后 / 之后,如果您使用 IOS 并且確實(shí)可以檢查您的 Shoucast 版本,則 Ios 只能重現(xiàn) Shoucast v2
添加回答
舉報(bào)