An implementation scheme of Android Network Radio Station
Source: Internet
Author: User
With the rapid development of electronic products, radio stations have almost moved away from people's entertainment life. With the rise of radio stations, Radio Stations gradually become available in the market and mobile phones If there is a network The usage of Radio software should be relatively high. Current mainstream smartphones In the Platform, iPhone and Symbian already have such software. Although the Android platform has not been launched for a long time, it has already been used, recently, I am also working on Android. I will introduce some of my experiences below.
Network Radio station type Current Network Radio websites are generally based on the following three protocols: MMS, RTSP, HTTP MMS is the network proposed by Microsoft. Streaming media protocols usually use files in the WMA format. Android currently does not support this Protocol, nor does it support the WMA format. The reason is obvious, competitors. RTSP is proposed by RealNetworks. Android supports this protocol, but this Protocol usually uses files in RM format, which is not supported by Android. HTTP Android is certainly supported, and this Protocol generally uses MP3 file format, which is also supported by Android. To sum up, we need to develop a network on Android Radio station software, you can only select the network in MP3 format of HTTP protocol Station websites, such websites mainly include Shoutcast and Icecast. These two categories have minor differences, basically the same. The following mainly describes ShoutCast. Mediaplayer Anyone familiar with Android may know that mediaplayer is a class used for media playback, and this class supports streaming media playback. This class supports protocols such as RTSP and HTTP, however, we cannot directly use this class to play the network. There are two main reasons for the radio station: 1. The ShoutCast station mentioned above does not directly adopt the HTTP protocol, and the mediaplayer cannot connect to the ShoutCast station normally. 2. the URL that mediaplayer can parse must be http ://............ /*. * format, that is, the URL must contain the file name. the URL of the ShoutCast station does not conform to this format. Therefore, some conversions are required. ShoutCast Protocol As mentioned above, the ShoutCast network station uses the HTTP protocol. In fact, this statement is not accurate. ShoutCast uses the ShoutCast protocol, which is slightly different from HTTP. The client and server The communication process is as follows: To the server Send a GET request with the following content: HTTP/1.0 User-Agent: androidinternetradio Accept: Audio/MPEG the server returns the following results: icy 200 OK (signifying that the server was successful) information channel icy-notice1: This stream requires Winamp (redundant notice) code of the activity app SC client connects to the network through the ShoutCast protocol radio station, obtain the radio audio data stream the HTTP server provides an HTTP connection to forward the audio data received by the scclient to the mediaplayer class Medi Aplayer audio playback class, access http: // 127.0.0.1/a.mp3: port and httpserver establish a connection to obtain data streams radioserver Network radio server develop a network on Android radio, the core part is to convert the ShoutCast protocol data stream into a mediaplayer class that can be played, that is, scclient and httpserver. This article only introduces the general implementation scheme, there are also some details in the specific encoding (for example, when the mediaplayer is connected to httpserver, A contentlenth value must be specified as Infinity.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.