如何在Android 2.3.3中使用MediaPlayer进行ShoutCast流式处理 [英] how to ShoutCast Streamming with MediaPlayer with android 2.3.3

查看:93
本文介绍了如何在Android 2.3.3中使用MediaPlayer进行ShoutCast流式处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,谢谢,

我整天都在论坛和互联网上寻找内容,对此我还一无所知.我不确定是否可能以直接和简单的方式.我一直读到自2.2以来就一直支持它,但我看不到它在哪个地方容易工作的示例

I have been all day looking forums and on internet and i'm not getting any clear about this. I am not sure if it possible in a direct and simple way. I read all time that since 2.2 it is supported natively but i don't see and example where it works easily

首先,我在网络上使用一些.mp3进行了测试,并且此代码运行良好:

First, i make some test with some .mp3 on a web and this code worked fine:

mp = new MediaPlayer();
mp.setDataSource(localContext, Uri.parse(SomeURL.mp3));     
mp.prepare();
mp.start()  

但是现在....我必须重播Stream音频,并且我只从shoutcast服务器获得了IP和端口,我正在尝试各种方法,但是每次我在媒体播放器中出现错误时(典型的情况) (0,-38)错误,一般.

but now....i have to reproduce Stream audio, and i have been given just an ip and port from a shoutcast server, i am trying all kind of things but all time i get error in media player, the typical (0,-38) error, general.

mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
//mp.setDataSource("http://xxx.xxx.xxx.xxx:xxxx");          
mp.setDataSource("http://xxx.xxx.xxx.xxx");
mp.prepareAsync();
mp.start()  --> it crashs here  

我不知道自己是否正确....第一次遇到流媒体问题....

i have no idea if i am doing it correct....first time i face stream issues....

是否有可能使之成为一种简单的方法?如果没有....解决方案是什么?

Is it possible to make it a easy way like that? if not....what are the solutions?

谢谢!!

推荐答案

在进行了两天的谷歌搜索后,没有太大结果,我发现了一个页面,其中包含许多公共流媒体URL

After two days of googling without much result, I found a page with a lot of public streaming url link and I tried some with the original code and in windows media player. Almost all of then didn't work on wmp but some yes...so I tried some of them, and the ones with link it didn't worked...but the ones with ip+port yes !! It seems the problem was with the ip+port i had for tests.... So my code is really simple finally.... and it works for a spanish radio.

if(!mp.isPlaying()){
  try{
    mp = new MediaPlayer();
    mp.setOnPreparedListener(this);
    mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
    url="http://91.121.92.186:8060";
    mp.setDataSource(url);
    mp.prepareAsync();
  }catch(IOException e){
    e.printStrackTrace();
  }
}

@Override
public void onPrepared(MediaPlayer mp) {
    mp.start();//Cuando acaba de cargar inicia la reproducción
}

这篇关于如何在Android 2.3.3中使用MediaPlayer进行ShoutCast流式处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆