WEB开发网
开发学院手机开发Android 开发 Android 网络电台的一种实现方案 阅读

Android 网络电台的一种实现方案

 2010-03-19 16:11:00 来源:WEB开发网   
核心提示:icy-notice1:This stream requires Winamp(redundant notice)icy-notice2:SHOUTcast Distributed Network Audio Server/posix v1.x.x(tells the client what server it is

icy-notice1:
This stream requires Winamp
(redundant notice)

icy-notice2:SHOUTcast Distributed Network Audio Server/posix v1.x.x
(tells the client what server it is and version)SHOUTcast Specific

icy-name:Unnamed Server (Name of the server)

icy-genre:Unknown Genre (what genre the server falls under)

icy-url:http://www.shoutcast.com (homepage for the server)

Content-Type:audio/mpeg (Content type of the stream to follow)

icy-pub:1 (whether the server is public or not)

icy-br:56 (bitrate of the server)

icy-metaint:8192 (if icy-metadata:1 was signified this was shown I will discuss this further later)

(end of header)

At this point the server begins sending the audio data(从这里开始发送音频数据).

可以看出ShoutCast服务器的Reponse与通常的HTTP协议不同,因此直接以HTTP协议方式进行连接不能够成功,需要自己写一套对应ShoutCast协议的处理。

上面介绍了一些相关的知识,下面介绍一下软件结构,如下图:

internet radio

Activity App画面部分代码

SC Client 通过shoutcast协议连接网络电台,获取电台音频数据流

HTTP Server 提供http连接,将SCClient接收到的音频数据转发给MediaPlayer类

MediaPlayer 音频播放类,通过访问http://127.0.0.1/a.mp3:port 与HTTPServer建立连接获取数据流

RadioServer 网络电台服务器

Android上开发网络收音机,核心部分在于将shoutcast协议的数据流转换为MediaPlayer类可播放的形式,也就是上图中的SCClient和HTTPServer,本文只是介绍了大体实现方案,具体编码中还会有一些细节问题(例如MediaPlayer连接HTTPServer时,需要有一个contentlenth,这个值应该指定为无穷大)需要解决。

上一页  1 2 

Tags:Android 网络电台 实现

编辑录入:coldstar [复制链接] [打 印]
赞助商链接