在Chrome的HTML5视频代码中通过php播放mp4文件? [英] Play mp4 file through php in HTML5 Video Tag in Chrome?

查看:577
本文介绍了在Chrome的HTML5视频代码中通过php播放mp4文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对mp4文件有问题. Html5 Video Tag可以通过直接链接播放,但不能与PHP Header一起播放(Mp3与PHP Header可以很好地工作).我已经尝试了Stack中几乎所有的解决方案,但仍然无法解决我的问题:(

I have a problem with mp4 files. Html5 Video Tag can play it with direct link, but not with PHP Header (Mp3 is worked fine with PHP Header). I have tried almost of solution in Stack but still not resolve my problem :(

听到的是我的代码:

PHP mp4.php

    error_reporting(0);

    $local_file = 'z.mp4';//'b.mp3';
    $download_file = 'out.mp4';
    // send headers
    header('Cache-control: private');
    header('Content-Type: video/mp4');
    header('Content-Length: '.filesize($local_file));
    header('Content-Disposition: filename='.$download_file);
    header('Accept-Ranges: bytes');
    header("Content-Transfer-Encoding: binary");
    readfile($local_file);

HTML

     <video controls="" autoplay="" name="media">
          <source src="http://localhost/videos/mp4.php" type="video/mp4">
     </video>

我不知道为什么:(请帮助我.

I don't know why :( Please help me.

谢谢

推荐答案

好!我已经解决了我的问题:)希望这可以帮助任何与我有相同问题的人

OK! I've resolved my problem :) Hope this will help anyone has the same problem as me

只需使用该代码:

$file = 'local_file';
$newfile = 'outFile';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($newfile));
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
}

这篇关于在Chrome的HTML5视频代码中通过php播放mp4文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆