Click here to Skip to main content
13,346,397 members (64,124 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 25 Jul 2005

Read raw SHOUTcast Stream

, 25 Jul 2005
Rate this:
Please Sign up or sign in to vote.
How to read raw SHOUTcast stream.


This is only a raw solution to grab a SHOUTcast stream from a server.

Using the code

'Imports System.Net
'Imports System.Text

Private Sub Button1_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
    SHOUTcast_Save("", "c:\song_raw.mp3")
End Sub

Public Function SHOUTcast_Save(ByVal sURL As String, _
                ByVal sFileName As String) As Boolean

    Dim webreq As System.Net.HttpWebRequest = _
                  CType(System.Net.WebRequest.Create(sURL), _

    webreq.Headers.Add("GET", "/stream/2001 HTTP/1.0")
    webreq.UserAgent = "WinampMPEG/5.09"
    webreq.Headers.Add("Icy-MetaData", "1")

    Dim webres As System.Net.WebResponse = webreq.GetResponse()

    Dim oReader As System.IO.Stream = webres.GetResponseStream()
    Dim oFile As System.IO.Stream = New System.IO.FileStream(sFileName, _
                 System.IO.FileMode.OpenOrCreate, _
                 System.IO.FileAccess.ReadWrite, System.IO.FileShare.None)

    For Each oHeader As System.Net.WebHeaderCollection In webres.Headers

        '(0)    "icy-notice1"    String
        '(1)    "icy-notice2"    String
        '(2)    "icy-name"       String
        '(3)    "icy-genre"      String
        '(4)    "icy-url"        String
        '(5)    "icy-pub"        String
        '(6)    "icy-metaint"    String  'how often the metadata 
        '                                    is sent in the stream
        '(7)    "icy-br"         String
        '(8)    "icy-irc"        String
        '(9)    "icy-icq"        String
        '(10)    "icy-aim"       String

        'icy-notice1 - An informational message. 
        'icy-notice2 - Another informational message, 
        '              probably "icy-notice3", "icy-notice4" etc.
        '              can also be used. 
        'icy-name - The name of the stream that the server is sending,
        '           this is usually displayed along with
        '           the current song title in clients. 
        'icy-genre - The genre of the music served. 
        'icy-url - An URL associated with the stream, 
        '          usually the homepage of the "webradio" or similar. 
        'icy-pub - Not sure, believe it indicates 
        '          if the stream is public or private 
        'icy-br - BitRate, seems mostly informational as most
        '         clients encountered seem to support VBR (Variable BitRate). 

    Dim b As Integer
    While True
        b = oReader.ReadByte()
        If b = -1 Then Exit While

        'ToDo: Get the metadata (Thanks to SmackFU 
        'Read the data stream as you normally would, 
        'keeping a byte count as you go. 
        'When the number of bytes equals the metadata 
        'interval, you will get a metadata block.
        'The first part of the block is a length specifier, 
        'which is the next byte in the stream. 
        'This byte will equal the metadata length / 16. 
        'Multiply by 16 to get the actual metadata length. 
        '(Max byte size = 255 so metadata max length = 4080.) 
        'Now read that many bytes and you will 
        'have a string containing the metadata. 
        'Restart your byte count, and repeat. Yay!
        'Note that the metadata length is set to 0 most 
        'of the time, meaning there is no metadata. 
        'The metadata is normally sent at two particular 
        'places: immediately after connecting and when 
        'the song changes. It seems as if some servers 
        'aren't real diligent about the former, 
        'so it might take a while to get your first block.
        'Also, be sure you don't count the bytes in the metadata 
        'length field or the metadata when you're figuring 
        'out whether you've hit the interval. Only the MP3 
        'data counts. So you can't be lazy and just keep 
        'a total byte count and mod it.

        'ToDo: Interpret the metadata
        'Part of the metadata string should look like this:
        'StreamTitle='title of the song';

    End While


End Function

Points of Interest

You see, that the metadata is not parsed. (This means you must not write all bytes.) Good Luck... :)


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Dani Forward
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionThe server committed a protocol violation. Section=ResponseStatusLine Pin
chrsarly044-Oct-07 13:40
memberchrsarly044-Oct-07 13:40 
AnswerRe: The server committed a protocol violation. Section=ResponseStatusLine Pin
dfrede5-Oct-07 7:28
memberdfrede5-Oct-07 7:28 
GeneralRe: The server committed a protocol violation. Section=ResponseStatusLine Pin
Martin Garmendia12-Jan-08 11:51
memberMartin Garmendia12-Jan-08 11:51 
GeneralRe: The server committed a protocol violation. Section=ResponseStatusLine Pin
Ducain25-Jun-08 8:59
memberDucain25-Jun-08 8:59 
GeneralRe: The server committed a protocol violation. Section=ResponseStatusLine Pin
George Cristian10-May-13 5:44
memberGeorge Cristian10-May-13 5:44 
This helped me to solve "The server committed a protocol violation. Section=ResponseStatusLine" but now I get another one :The remote server returned an error: (401) Unauthorized.

what to do ?

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 26 Jul 2005
Article Copyright 2005 by Dani Forward
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid