Headers in the file and assorted other fun stuff may make such things hard, but it's possible for mp3's at least.
If you're running apache with php as a module (won't work otherwise), you can try this function that I use for a very slimmed down "webcasting" page. The resume part of the function can be altered to start playing from a specified offset without too much pain, but I'll leave the actual calculation of said offset to you. =)
As for players, winamp has no trouble with the code below. No real experience with anything else, but friends said xmms under linux worked fine as well.And again, this will only work with Apache running PHP as a module, since it uses getAllHeaders().
function sendfile($file) {
// $file should be the complete path+filename to a mp3-file
$filename = basename($file);
$fsize = filesize($file);
$headers = getAllHeaders();
// normal download
if(!isset($headers["Range"])) {
header("Accept-Ranges: bytes");
header("Content-Length: $fsize");
header("Content-Type: audio/mpeg");
header("Content-Disposition: attachment; filename=$filename");
$fp = fopen($file, "rb");
while(!feof($fp)) {
$buffer = fread($fp, 4096);
print $buffer;
}
fclose($fp);
exit;
}
// resume requested, do magic
else {
$val = split("=", $headers["Range"]);
if(ereg("-", $val[1])) {
$slen = ereg_replace("-", "", $val[1]);
$sfrom = $fsize - $slen;
$requestedsize = $slen;
}
else if(ereg("-$", $val[1])) {
$sfrom = ereg_replace("-", "", $val[1]);
$slen = $fsize - $sfrom;
$requestedsize = ((int)$fsize-(int)$sfrom);
}
$br = $sfrom . "-" . (string)($fsize-1) . "/" . $fsize;
header("HTTP/1.1 206 Partial content");
header("Content-Length: $requestedsize");
header("Content-Range: bytes $br");
header("Content-Type: audio/mpeg");
header("Content-Disposition: attachment; filename=$filename");
$fp = fopen($file, "rb");
fseek($fp, $sfrom);
while(!feof($fp)) {
$buffer = fread($fp, 4096);
print $buffer;
}
fclose ($fp);
exit;
}
}