开发者

Android playing live radio stream?

Can anyone please suggest me how to play live radio stream url in and开发者_运维技巧roid. Someone who has experience in playing live radio url in android.

Thanks


 try
   {
        MediaPlayer media = new MediaPlayer();
        media.setAudioStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
        media.setDataSource("http://indiespectrum.com:9000");
        media.prepare();
        media.start();

    }
    catch(Exception e)
    {
        //Getting Exception
    }


    public void startRadio(String streamUrl) {
       MediaPlayer mPlayer = new MediaPlayer();
       mPlayer.setOnErrorListener(
            new MediaPlayer.OnErrorListener() {
                public boolean onError(MediaPlayer mp, int what, int extra) {
                    Log.e(getClass().getName(), "Error in MediaPlayer: (" + what +") with extra (" +extra +")" );
                }
            });

    try {
        mPlayer.setDataSource(streamUrl); 
        mPlayer.prepare();
        mPlayer.start();
    } catch (IllegalArgumentException e) {
        Log.e(getClass().getName(), "IllegalArgumentException");
    } catch (IllegalStateException e) {
        Log.e(getClass().getName(), "IllegalStateException");
    } catch (IOException e) {
        Log.e(getClass().getName(), "IOException");
    }
}

Quick copy paste ..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜