header for ipod touch to download a mp4 file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mickey9801
Forum Newbie
Posts: 3
Joined: Sat Oct 13, 2007 2:54 am

header for ipod touch to download a mp4 file

Post by mickey9801 »

Hi all. I am trying to develop a web application like http://vtap.com or Google video which let user to download and playback mp4 file through Safari browser bundled with iPod touch. I can download and playback a mp4 file correctly when I access the file directly by URL (I put the mp4 file in a public area). But when I try to use a simple file proxy program to read the same file at same location and transmit it to iPod touch, it doesn't playback correctly. Everything goes fine in PC (Firefox). I think it would be a problem in header but I don't know what should I put into.

My test program is as below (http://dev.crossmedia.com.hk/ipod/stream.php):

Code: Select all

<?php
$filename = "./ef_mv_320_h264b.mp4";
$filesize = filesize($filename);
$mime_type = 'video/mp4';

header("Expires: Mon, 26 Nov 1962 00:00:00 GMT");
header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, private, must-revalidate, max-age=0");
header("Pragma: no-cache");
header('Content-Length: '.$filesize);
header('Content-Type: '.$mime_type);
header('Content-Disposition: attachment; filename="'.basename($filename).'"');

$fp = fopen($filename,"r");
while (!feof($fp)) {
	echo fread($fp, 8192);
}
fclose($fp);
?>
Hope anyone can help me. Thank you.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Maybe using a add-on in Firefox, like Web Developer may shed some light on what headers the server is sending when directly accessing the file. Worst case, you can use a emulated browser to fetch the headers. If you're running PHP 5 (at least temporarily) you can use get_headers().
mickey9801
Forum Newbie
Posts: 3
Joined: Sat Oct 13, 2007 2:54 am

Post by mickey9801 »

I have used firebug and Live HTTP headers extension to check the header but they both seems not to record header of direct file download. I think there was nothing special on direct file download condition.

When I visit vTap and Google video. They seems have checked my browser type and just transmit the file as usually to Firefox.

Unfortunately, I am using a php 4.3.13 server. I will try to move my test files to a php5 platform.
mickey9801
Forum Newbie
Posts: 3
Joined: Sat Oct 13, 2007 2:54 am

Post by mickey9801 »

I have checked access log of my server and found that each time I access the stream.php, ipod touch safari will access the file twice. The user agent of first access is "Apple iPhone" and the second access is "iPod Safari"...

Code: Select all

xxx.xxx.xxx.xxx - - [14/Oct/2007:04:10:53 +0800] "GET /ipod/stream.php HTTP/1.1" 200 16384 "-" "Apple iPhone v1.1.1 CoreMedia v1.0.0.3A110a"
xxx.xxx.xxx.xxx- - [14/Oct/2007:04:10:52 +0800] "GET /ipod/stream.php HTTP/1.1" 200 270336 "-" "Mozilla/5.0 (iPod; U; CPU like Mac OS X; ja-jp) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A110a Safari/419.3"
The amount of data logged in access log is not the same of the file. Seems it stopped to transfer data suddenly.

I have also tried to change the reading method from fread() to readfile(), so that the file will not transfer in segment. Now the amount of data logged in the access log is same as the mp4 file size, but iPod touch still cannot playback the file. The access log is like this :

Code: Select all

xxx.xxx.xxx.xxx- - [14/Oct/2007:04:24:17 +0800] "GET /ipod/stream.php HTTP/1.1" 200 5027707 "-" "Apple iPhone v1.1.1 CoreMedia v1.0.0.3A110a"
xxx.xxx.xxx.xxx- - [14/Oct/2007:04:24:17 +0800] "GET /ipod/stream.php HTTP/1.1" 200 5027707 "-" "Mozilla/5.0 (iPod; U; CPU like Mac OS X; ja-jp) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3A110a Safari/419.3"

P.S. the sequence of 2 accesses are not always in the same order.
Post Reply