We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
源的 URL 为: http://shoutcast2.omroep.nl:8104/
初始化MediaPlayer,你需要几行代码。现在
,MediaPlayer 对象已初始化,您可以开始流式传输了。好吧,实际上不是。您将需要发出 MediaPlayer 的准备命令。有两种变体。
1.准备():这是一个同步调用,它会被阻塞,直到MediaPlayer对象进入准备状态。如果您尝试播放需要 MediaPlayer 更长时间的本地文件,这是可以的,否则您的主线程将被阻塞。
prepareAsync():顾名思义,这是一个异步调用。它立即返回。但是,这显然并不意味着 MediaPlayer 已经准备好。您仍然需要等待它进入准备状态,但由于此方法不会阻塞您的主线程,因此当您尝试从其他地方流式传输某些内容时,可以使用此方法。当 MediaPlayer 通过 onPrepared(MediaPlayer mp) 方法准备好时,您将收到回调,然后就可以开始播放了。
因此,对于我们的示例,最佳选择是:
2。 player.prepareAsync();
您需要将侦听器附加到 MediaPlayer 以在准备好时接收回调。这是代码。
The URL for the source is: http://shoutcast2.omroep.nl:8104/
To initialize the MediaPlayer, you need a few lines of code. There you go:
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(): 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. 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.