zoukankan      html  css  js  c++  java
  • 网络电台-SHOUTcast

    网络电台种类

      目前的网络电台网站一般是基于以下三种协议的:

      mms、rtsp、http

      其中mms是微软公司提出的网络流媒体协议,通常采用wma格式的文件,Android现在还不支持这种协议,也不支持wma格式,原因比较明显,竞争对手嘛。

      rtsp是RealNetworks公司提出的,Android是支持这种协议的,但是这种协议通常采用rm格式的文件,Android是不支持的。

      http协议Android是肯定支持的,而且这种协议一般采用mp3的文件格式,Android也支持。

      综上,我们要在Android上开发网络电台软件,那么只能选择http协议 mp3格式的网络电台网站,这样的网站主要包括shoutcast和icecast两大类。这两类有微小差别,基本上是相同的,下面主要以 shoutcast为主进行说明。

      MediaPlayer

      熟悉Android的人可能都知道有MediaPlayer这样一个类,用于媒体播放,而且这个类是支持流媒体播放的,这个类支持的协议包括rtsp、http等,但是我们还不能直接用这个类来播放网络电台,主要有两个原因:

      1.上面提到的shoutcast电台并不是直接采用http协议,MediaPlayer无法正常连接到shoutcast电台

      2.MediaPlayer 能够正常解析的URL必须是http://............/*.*的形式,也就是说url中必须包括文件名,shoutcast电台的url不符合这样的形式.

      因此需要做一些转换的工作。

      shoutcast协议

      上面已经提到,shoutcast网络电台是采用http协议的,其实这种说法并不准确,shoutcast电台采用的是shoutcast协议,这种协议与http略有不同,客户端与服务器间通讯过程如下:

      向服务器发送GET请求,内容如下:

      HTTP/1.0

      User-Agent:AndroidInternetRadio

      Accept:audio/mpeg

      服务器端返回如下:

      ICY 200 OK (signifying that the server was successful)

    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协议的处理。

    http://zh.wikipedia.org/wiki/SHOUTcast

    SHOUTcast是由Nullsoft研發、支援多個作業系統、免費的聲音串流科技,用於網路廣播。

    SHOUTcast使用MP3或是AAC將聲音編碼,由HTTP作為傳送協定。

    SHOUTcast的使用者可建立自己的網路廣播電台,許多軟體都可以收聽該廣播輸出的格式,包括Nullsoft WinampXMMS,以及蘋果電腦的iTunes。目前可作的用途包含了聽音樂、看影片以及收聽現場直播。

    用途

    最常見的用途就是以SHOUTcast製作網路廣播。比起傳統的AM調幅或FM調頻廣播,SHOUTcast不僅便宜,技術門檻也較低,更不受到政府管理頻譜的影響。同時,傳統的廣播電台也利用SHOUTcast將版圖延伸到網路上,讓聽眾在收不到電波的地方(例如地下室)、地下電台蓋台嚴重或是該廣播電台的訊號涵蓋範圍以外的地區及國外仍可利用網路來收聽。

    批評

    VLC media player的開發團隊指出SHOUTcast的合約禁止將SHOUTcast使用在任何開放原始碼自由軟體中,同時必須夾帶SHOUTcast Radio Toolbar(該團隊認為此程式屬於廣告間諜軟體),因此在VLC Player 1.1.0版後移除了SHOUTcast的支援[1]

    shoutcast 例子分析

    http://blog.csdn.net/wertcsdn/article/details/2213374

    注:此例子为塞班s60的一种实现

  • 相关阅读:
    Interview with BOA
    Java Main Differences between HashMap HashTable and ConcurrentHashMap
    Java Main Differences between Java and C++
    LeetCode 33. Search in Rotated Sorted Array
    LeetCode 154. Find Minimum in Rotated Sorted Array II
    LeetCode 153. Find Minimum in Rotated Sorted Array
    LeetCode 75. Sort Colors
    LeetCode 31. Next Permutation
    LeetCode 60. Permutation Sequence
    LeetCode 216. Combination Sum III
  • 原文地址:https://www.cnblogs.com/jingzhishen/p/3659165.html
Copyright © 2011-2022 走看看