Jump to content

Poor man's MP3 streaming server


dillonlim
 Share

Recommended Posts

I got bored at work so I whipped up a simple script to stream my mp3s from one location to another. Pretty self explanatory. Place script in the same folder as your mp3s. Start up the script, then launch Winamp. From within Winamp, select "Play", "URL". Type in "http://<ip address of machine running the script>:51511" and it should start streaming the mp3.

#include <File.au3>
#include <Array.au3>

TCPStartUp()
Local $TCPport = "51511"
$msock = TCPListen(@IPAddress1, $TCPport)
If $msock = -1 Then
    MsgBox(0, "Error", "Unable to start server on port " & $TCPport)    
    Exit
EndIf

$mp3list = _FileListToArray(@ScriptDir, "*.mp3", 1)
$i = 0

While 1
$csock = TCPAccept($msock)
If $csock <> -1 Then

    If $i = $mp3list[0] Then
        $i = 1
    Else
        $i = $i + 1
    EndIf

    TCPSend($csock, "ICY 200 OK" & @CRLF)
    TCPSend($csock, "icy-name: " & $mp3list[$i] & @CRLF)
    TrayTip("Simple MP3 Streamer", $mp3list[$i], 10)
    $open = FileOpen($mp3list[$i], 16)

    Do

        $data = FileRead($open, 8)
        If StringLen($data) = "0" Then
            Sleep(5000)
        EndIf
        $packetsend = TCPSend($csock, $data)
        If $packetsend = "0" Then ExitLoop

    Until StringLen($data) = "0"
    TCPCloseSocket($csock)

EndIf
WEnd

TCPShutdown()
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...