问题
Thanks to all of you in advance :)
I want to make it clear before you start reading that I want to develop an android based app to use android device as a broadcaster, which records sound using its mic and sent it to shoutcast server something like this:
Android Device with internet connection -> Shoutcast Server -> listeners.
So please do not get confused with playing shoutcast streams on android, because I do not want to develop a player to play an stream. If you are looking for developing a player then download source code from given link, it worked fine for me. Click to download Source code.
Now back to my question, I googled a lot in last two weeks and found This article, which helped me to use builtin mic of android device and stream over a local network. One can listen the stream using VLC.
But I want to send up-stream to my shoutcast server same as one can use winamp with DSP plugin and the problems are:
If I use the code from above This link, it works fine on local n/w but when I try to configure it with my shoutcast server, it gives error :
![UnknownHostException]
in log of eclipse.Is there any url based system on shoutcast server, to which if I will send a stream then it will get the stream and broadcast to my listeners? e.g. if I want to listen stream (down streaming), i can use
http://xx.example.com:1234;stream.mp3
and I am asking for up-streaming.How I can establish a connection to server by login/password. I want to do similar to DSP Plugin as shown in image attached.
回答1:
The code you linked to is not appropriate in this case. It appears to be for sending raw audio data over UDP, which is not at all what SHOUTcast uses.
SHOUTcast servers do not have an HTTP interface to stream to. They use a completely separate protocol which you must use if you need to use SHOUTcast servers. (I should note that Icecast just added HTTP PUT support within the last year or so.)
Fortunately, the SHOUTcast source protocol is quite simple. All you need to do is send your password, followed by a line break. If you get a favorable response from the server, then send your icy-*
headers followed by two line breaks, and followed by your encoded audio data. I have outlined this in detail when this question was asked for iOS a couple years ago: https://stackoverflow.com/a/9241620/362536 You can see the protocol yourself by using a packet sniffer like Wireshark and running it while you connect the Winamp SHOUTcast DSP (or other SHOUTcast source client) to your server.
Finally, don't forget to use an appropriate codec. With SHOUTcast, it's best to use either MP3 (as-is), or an AAC stream wrapped in ADTS. When I tried this project awhile back, I had a hard time figuring out how to get the audio encoded properly, as at least Android 2.1 didn't seem to have a way to encode to a stream and not to a file. I'm no Android dev though, so maybe you will find a better way!
回答2:
Change the code from
UnknownHostException ()
to
UnknownHostException(hostname)
where hostname is the name of the server on the internet. Probably a dns or routing issue. Pass the hostname to
getByName
or better yet
getAllByName
, log it, and verify it is the expected IP address (es).
This should add more info to the eclipse log.
来源:https://stackoverflow.com/questions/24709739/stream-from-android-device-to-shoutcast-upstreaming