I got bored, so I decided to mess around with my webserver. I noticed I had the song "The Ballad of Bilbo Baggins" by Leonard Nimoy on my server. So, I made a simple one-line script that opened that file using readfile(). I used Winamp's built-in networking feature to read it as a streaming server; lo-and-behold, it opened it and was actually streaming it (I watched as data accumulated).
I then wrote a short little loop that picked a random file off of my MP3 drive, and then opened that. I also toyed around with the Content-Disposition and got it to stream the filename however I pleased. I came up with this code as the server:
<?php
$path = "e:\\";
$files = array();
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
$files[$i] = $file;
$i ++;
}
closedir($dir_handle);
$num = rand(0,count($files));
$file = $files[$num];
$file = ereg_replace(".mp3","",$file);
$streamname = $file." [Mordecai's Sever]";
header("Content-type: audio/mpeg");
header("Content-Disposition: attachment; filename=$streamname");
readfile("e:\\$file.mp3");
unset($files);
?>
My question, to anyone who may know, is how would one go about streaming from a certain part of a file (much like ShoutCast), or perhaps multiple files, one after the other. Currently, Winamp disconnects after the file is done, and reconnects, as it is the only "song" in the playlist.
This works fine, but it opens the file each time from the beginning. I don't really care where this goes, but I want to know how to make a sort of ShoutCast server.
Ideas, anyone?
Edit: For some odd reason, the MB stripped the escaped slashes. All the code is bug-free.