mp4 file through php not playing as html5 video

I am trying to output an mp4 video file through PHP. When it is used through a flash player (eg. flowplayer) it is working great. But when I'm trying to use it as a source on an html5 video tag or to call directly the php file, it doesn't work.

The code I use is the following:

        $filesize = filesize($file);
        header("Content-Type: video/mp4");

        if ( empty($_SERVER['HTTP_RANGE']) )
        {
            header("Content-Length: $filesize");
            readfile($file);
        }
        else //violes rfc2616, which requires ignoring  the header if it's invalid
        {   
            rangeDownload($file);
        }

and rangeDownload function is from http://mobiforge.com/developing/story/content-delivery-mobile-devices Appendix A.

Even when I use a Content-Range header (Content-Range:bytes 0-31596111/31596112), it stucks on downloading 30.13 MB of the video.

Answers


Finally I've found a way to make it work

header("Content-Type: $mediatype");

if ( empty($_SERVER['HTTP_RANGE']) )
{
    header("Content-Length: $filesize");

    $fh = fopen($file, "rb") or die("Could not open file: " .$file);

    # output file
    while(!feof($fh))
    {
         # output file without bandwidth limiting
        echo fread($fh, $filesize);
    }
    fclose($fh);
}
else //violes rfc2616, which requires ignoring  the header if it's invalid
{   
     rangeDownload($file);
}

It is working in direct link of the php file and inside html5 video tag. But in order to work in Flowplayer (and maybe in other flash/html5 players) you need to add a mp4 extension (eg. view.php?id=XXX&file=type.mp4)


Need Your Help

Who is preventing the release of Java 1.7?

java java-7 jsr

I recently attended a talk by a Sun engineer, Charlie Hunt, regarding performance. The talk was interesting enough but one question was regarding the release date of 1.7.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.