0

I am storing my videos outside of web root, and stream them on request. It works perfectly in firefox and chrome - but fails in IE, safari (mac) and iPad. IE Reports Error: Unsupported video type or file path

The request is made like so:

<video width="600" height="300">
<source src="http://myserver.com/getVideo?key=<somehash>&file=video.mp4 type="video/mp4">
</video>`

however if I call the video directly (without streaming, and the location is in web root), it works in every browser, as expected. I believe it has something to do with the way I am streaming. Any ideas?

public function actionGetvideo(){
    $filename = $_GET['file'];
    $filepath = $_GET['path'];

    if ($_GET['k'] != $this->gen_access_key($filename)) {
        throw new CHttpException(403, "unauthorized 1");
        exit('access key fail');
    }
    $filepath = '/home/columbin/' . $filepath . $filename;
    if (!file_exists($filepath)) {
        throw new CHttpException(404, "This video does not exist");
        exit('file does not exist');
    }

    $content_type = 'video/mp4';
    $filesize = filesize($filepath);
    $fp = fopen($filepath, 'r');
    if (!$fp) exit('no file');

    $content_length = $filesize;
    header('Content-Type: '.$content_type);
    header('Content-length: '.filesize($full_request_path));

    ob_clean();
    flush();
    $this->readfile_chunked($filepath);
}

protected function readfile_chunked($filename,$retbytes=true) {
    $chunksize = 1*(1024*1024); // how many bytes per chunk
    $buffer = '';
    $cnt =0;
    $handle = fopen($filename, 'rb');
    if ($handle === false) {
        return false;
    }
    while (!feof($handle)) {
        $buffer = fread($handle, $chunksize);
        echo $buffer;
        ob_flush();
        flush();
        if ($retbytes) {
            $cnt += strlen($buffer);
        }
    }
    $status = fclose($handle);
    if ($retbytes && $status) {
        return $cnt; // return num. bytes delivered like readfile() does.
    }
    return $status;

}
visevo
  • 791
  • 7
  • 23
  • You probably just have a codec not supported by all of your browsers. When you plug in the URL, you aren't always using the browser's built-in playback capability. You often use a plugin instead, which isn't available with HTML5. – Brad Mar 06 '14 at 19:26
  • I don't think so - this problem only occurs when the video is attempted to be streamed. If I change the video src to a video in webroot it plays just fine. – visevo Mar 06 '14 at 19:30
  • That's still streaming.... Why don't you use `readfile()`, or hand it off to your web server? – Brad Mar 06 '14 at 19:45
  • Could you be more specific? – visevo Mar 06 '14 at 20:24
  • `readfile()` is a function to read the file from disk and output to the buffer. The best thing to do though is let the server take care of this for you with sendfile or equivalent. http://wiki.nginx.org/HttpCoreModule#sendfile – Brad Mar 06 '14 at 20:25

1 Answers1

1

I think I found a solution for you: here
I believe your problem has to do with headers not being set correctly. Look at the second answer. Hope it works.

Community
  • 1
  • 1