Stream m4v to iPhone using PHP

I'm having a problem setting up a stream using PHP for the iPhone. I have my .m4v files in a non web-accessible directory, so I use PHP to read the file and output it using this code:

$iFile = "/full/path/to/file.m4v;
header('Content-Type: video/x-m4v');
header('Content-Disposition: inline; filename="'.basename($iFile).'"');
header('Content-Length: '.filesize($iFile));
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
readfile($iFile);
exit;

This works fine in any standard browser, however, on the iPhone, I get a message saying:

"This movie format s not supported."

Anyone have any ideas about streaming from PHP to an iPhone?

I'm using PHP 5 and Apache for the webserver.

Posted on Aug 7, 2008 8:15 AM

Reply
5 replies

Aug 17, 2008 12:25 PM in response to docmattman

I'm facing the same problem, albeit with .mp3 files. I don't have an answer for you, but if I find it, I'll reply back.

I've tried at least the following so far:

1) Placed the .mp3 in my server's document root and accessed the file directly with Mobile Safari. This works, confirming that Mobile Safari has no problems just loading and playing an .mp3 file via HTTP per se.
2) Compared the HTTP headers emitted by the server when doing the above with the headers emitted when outputting the file via PHP. Adjusting the latter to match the former makes no difference.
3) Using an alternate content-type ("audio/x-mp3" instead of "audio/mpeg"). Doesn't help.
4) Using fpassthru() instead of readline(). Pointless.
5) Wrapping fread() in a while loop and chunking the output. No difference.

Message was edited by: cobra libre

Sep 17, 2008 4:59 AM in response to docmattman

I had the same problem, here is the trick Apple iPhone uses HTTP byte-ranges for requesting audio and video files. First, the Safari Web Browser requests the content, and if it's an audio or video file it opens it's media player. The media player then requests the first 2 bytes of the content, to ensure that the Webserver supports byte-range requests. Then, if it supports them, the iPhone's media player requests the rest of the content by byte-ranges and plays it. So you have to write your script providing working PHP code which supports byte-range download. more info at: http://mobiforge.com/developing/story/content-delivery-mobile-devices

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Stream m4v to iPhone using PHP

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.