如何在android中播放在线广播 [英] How to play online radio in android

查看:32
本文介绍了如何在android中播放在线广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发 android 应用程序,我可以在其中播放在线广播流.我已经完成了媒体播放器课程,但我认为没有任何方法可以在线播放广播.如果有人知道这件事,请帮助我.

I am working on android application in which i have play online radio streaming. i have gone through the media player classes but i don't think is there any method to online streaming of radio. If any know about this please help me.

谢谢.维克拉姆

推荐答案

Vikram,

您应该能够使用 MediaPlayer 实现此目的;但是,根据您的格式,这可能很困难.例如,如果您尝试播放使用 .pls 或 .m3u 的在线广播流,则必须解析该文件,并提取要使用的真实网址.

You should be able to achieve this using the MediaPlayer; however, depending on your format it may be difficult. For example, if you're trying to play an online radio stream that uses .pls, or .m3u, you would have to parse that file, and pull out the true URLs to use.

除此之外,您应该能够使用带有 URL 的 MediaPlayer 的 create 方法来开始流式播放.请记住,如果流 URL 重定向(它可能会重定向),您可能必须解析 URL.一个简单的方法是使用 HttpURLConnection 打开一个连接,然后是 connect(),然后是 getURL().您可能需要一个字符串 url,因此对 getURL() 的结果调用 toExternalForm().

Beyond that, you should be able to use MediaPlayer's create method with a URL to start streaming playback. Keep in mind that if the streams URL redirects (which it likely does) you may have to resolve the URL. A simple way to do this is use HttpURLConnection to open a connection, then connect(), then getURL(). You'll likely need a string url, so call toExternalForm() on the result from getURL().

此外,如果通过 URL 使用 MediaPlayer 对您不起作用,您可能需要想出自己的缓冲机制来从服务器获取数据.既然如此,你可以试试这个教程:http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/

Additionally, If things aren't working for you with MediaPlayer via URL, you might have to come up with your own buffering mechanism to get the data from the server. That being the case, you can try this tutorial: http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/

这篇关于如何在android中播放在线广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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