为了账号安全,请及时绑定邮箱和手机立即绑定

mediaplayer 不播放广播电台流

mediaplayer 不播放广播电台流

翻翻过去那场雪 2022-06-23 20:11:10
我正在尝试安装一个可以与广播链接一起使用的流媒体播放器,但它对我不起作用。我想知道错误可能是什么,我附上了代码和链接。谢谢你。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 streamingboolean 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    }任何合作将不胜感激,因为我只希望音频流开始
查看完整描述

2 回答

?
忽然笑

TA贡献1806条经验 获得超5个赞

您可以使用prepareAsyc()准备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();

        }

    });


}


查看完整回答
反对 回复 2022-06-23
?
一只萌萌小番薯

TA贡献1795条经验 获得超7个赞

您只需将http://xxx.xx.xxx.x/更改为http://xxx.xx.xxx.x/;stream.mp3可以是任何单词,重要的是放; 在您的 shoucast url 之后 / 之后,如果您使用 IOS 并且确实可以检查您的 Shoucast 版本,则 Ios 只能重现 Shoucast v2



查看完整回答
反对 回复 2022-06-23
  • 2 回答
  • 0 关注
  • 150 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号