hi everyone.
I am not very good at English...Please understand me.
I am trying to stream audio (only formatted mp3) files to iTouch,
iPhone through WI-FI.
it works with 'content-Range header()' in PHP platform.
it works good on iTouch, but working on iPhone? it doesn't,
Unfortunately.
in case of iPhone, if the stream-file type is VBR, it gets wrong play
time.
/*ex.
/* file-type: VBR
/* real-playtime: 0:55
/* iPhone-playtime: 1:08 (and it downloads only 55 seconds in progress
bar)
/* iTouch-playtime: 0:55
here is the source...
<php
ob_start();
$md5 = $_GET['md5'];
$URL = "http://medme.next.com/".$md5.".mp3";
header("ETag: ".$md5.":3173");
$conn = DBConn("DATABASES"); //custom function
$query = "SELECT FILESIZE FROM TABLE1 WHERE MD5 = '{$md5}'";
$resource = mysql_query($query, $conn);
DBexit($conn);
$Size = mysql_result($resource, 0, 0);
rangeDownload($URL, $Size);
function rangeDownload($file, $length) {
$fp = @fopen($file, 'rb');
$size = $length; // File size
$length = $size; // Content length
$start = 0; // Start byte
$end = $size - 1; // End byte
if (isset($_SERVER['HTTP_RANGE'])) {
$c_start = $start;
$c_end = $end;
list(, $range) = explode('=', $_SERVER['HTTP_RANGE'],
2);
if (strpos($range, ',') !== false) {
header('HTTP/1.1 416 Requested Range Not
Satisfiable');
header("Content-Range: bytes
$start-$end/$size");
exit;
}
if ($range[0] == '-') {
$c_start = $size - intval(substr($range, 1));
} else {
$range = explode('-', $range);
$c_start = intval($range[0]);
$c_end = (isset($range[1]) &&
is_numeric($range[1])) ? $range
[1] : $end;
}
$c_end = ($c_end > $end) ? $end : $c_end;
if ($c_start > $c_end || $c_start > $size - 1 || $c_end
>= $size) {
header('HTTP/1.1 416 Requested Range Not
Satisfiable');
header("Content-Range: bytes
$start-$end/$size");
exit;
}
$start = $c_start;
$end = $c_end;
$length = $end - $start + 1;
fseek($fp, $start);
header('HTTP/1.1 206 Partial Content');
header('Accept-Ranges: bytes');
header("Content-Length: ".$length);
header("Content-Range: bytes
".$start."-".$end."/".$size);
header("Content-Type: audio/mpeg");
header("Expires: 0");
}else{
header('Accept-Ranges: bytes');
header("Content-Length: ".$length);
header("Content-Type: audio/mpeg");
header("Expires: Mon, 20 Dec 1977 00:00:00 GMT");
}
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-Disposition: attachment;filename=test.mp3");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$buffer = 1024;
while(!feof($fp) && ($p = ftell($fp)) <= $end) {
if ($p + $buffer > $end) {
$buffer = $end - $p + 1;
}
echo fread($fp, $buffer);
ob_flush();
flush();
}
fclose($fp);
while(@ob_end_clean());
}
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"iPhoneWebDev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/iphonewebdev?hl=en
-~----------~----~----~----~------~----~------~--~---