mediaplayer不播放shoutcast无线电流

问题描述 投票:0回答:1

我正在尝试安装一个与shoutcast链接一起工作的流媒体播放器,但它对我不起作用。我想知道错误是什么,我附上了代码和链接。谢谢。

public class PrincipalActivity extends Activity {

    //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);

        new PlayerTask().execute(stream); //llamara a quien reproducira el audio
    }

    class PlayerTask extends AsyncTask<String, Void, Boolean> {
        @Override
        protected Boolean doInBackground(String... strings) {
            try {
                mediaPlayer.setDataSource(strings[0]);
                mediaPlayer.prepare();
                prepared=true;
            } catch (IOException e) {
                e.printStackTrace();
            }
            return prepared;
        }

        @Override
        protected void onPostExecute (Boolean aBoolean){
            super.onPostExecute(aBoolean);
            //btnPlay.setBackground(R.mipmap.pause);
            mediaPlayer.start();
         }
     }
 }

任何合作都将受到赞赏,因为我只想要开始音频流

java android android-mediaplayer android-studio-3.0
1个回答
1
投票

你可以使用qazxsw poi来准备媒体播放器。

试试这段代码。

prepareAsyc()
© www.soinside.com 2019 - 2024. All rights reserved.