Android的 - 互联网广播流 [英] Android - internet radio streaming

查看:148
本文介绍了Android的 - 互联网广播流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刨,使一个Android应用程序一个地方广播电台 我需要让互联网流媒体广播节目 可否请您提供一些起点,对此,有教程什么的。

I am planing to make a android app for one local radio station I need to make internet streaming of radio program Can you please provide some starting point for this, some tutorial or something.

推荐答案

的URL来源: HTTP://shoutcast2.omroep .NL:8104 /

要初始化的MediaPlayer,你需要code几行。你去那里:

To initialize the MediaPlayer, you need a few lines of code. There you go:

MediaPlayer player = new MediaPlayer();
player.setDataSource("http://shoutcast2.omroep.nl:8104/");

现在的MediaPlayer对象初始化,你就可以开始流。好吧,实际上不是。您将需要发出MediaPlayer的prepare命令。有这2个版本。

Now that the MediaPlayer object is initialized, you are ready to start streaming. Ok, not actually. You will need to issue the MediaPlayer's prepare command. There are 2 variations of this.

1。 prepare():这是一个同步调用,而阻塞,直到MediaPlayer对象进入了prepared状态。这是好的,如果你正在尝试播放本地文件将采取MediaPlayer的时间越长,否则你的主线程将被阻止。 prepareAsync():这是,顾名思义,异步调用。它立即返回。但是,这obvisouly,并不意味着MediaPlayer正在ppared尚未$ P $。你仍然要等待它进入prepared状态,但由于这种方法不会阻止你的主线程,则可以使用此方法,当你正试图从其他地方流了一些内容。你会得到一个回调,在MediaPlayer已准备好通过prepared(MediaPlayer的MP)方法,然后,播放就可以开始。 因此,对于我们的例子中,最好的选择是:

1. prepare(): This is a synchronous call, which is blocked until the MediaPlayer object gets into the prepared state. This is okay if you are trying to play local files that would take the MediaPlayer longer, else your main thread will be blocked. prepareAsync(): This is, as the name suggests, an asynchronous call. It returns immediately. But, that obvisouly, doesn't mean that the MediaPlayer is prepared yet. You will still have to wait for it to get into the prepared state, but since this method will not block your main thread, you can use this method when you are trying to stream some content from somewhere else. You will get a callback, when the MediaPlayer is ready through onPrepared(MediaPlayer mp) method, and then, the playing can start. So, for our example, the best choice would be:

2。 。玩家prepareAsync(); 你需要一个监听器附加到的MediaPlayer接收回调时,它是prepared。这是code为。

2. player.prepareAsync(); You need to attach a listener to the MediaPlayer to receive the callback when it is prepared. This is the code for that.

player.setOnPreparedListener(new OnPreparedListener(){
            public void onPrepared(MediaPlayer mp) {
                     player.start();
            } 
});

这篇关于Android的 - 互联网广播流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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