微信无法播放php输出的视频流
巴扎黑
巴扎黑 2017-04-11 10:35:26
[PHP讨论组]

php代码:

    $fp = @fopen($file, 'rb');

    // 获取文件大小
    $size   = filesize($file); // File size
    $length = $size;           // Content length
    // 开始读取的位置
    $start  = 0;               // Start byte
    // 文件结尾
    $end    = $size - 1;       // End byte

    // 设置缓存
    header("Cache-Control:max-age=604800");
    header('Etag: ' . md5($file));
    header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
    
    $length = $end - $start + 1; // Calculate new content length
    fseek($fp, $start);
    header('HTTP/1.1 206 Partial Content');

    // TODO 暂时写死测试
    header('Content-Type:video/mp4');
    header("Content-Range: bytes $start-$end/$size");
    header("Content-Length: $length");
    
    $buffer = 1024 * 8;
    while(!feof($fp) && ($p = ftell($fp)) <= $end) {
        if ($p + $buffer > $end) {
            $buffer = $end - $p + 1;
        }

        echo fread($fp, $buffer);
        // Free up memory.
        // Otherwise large files will trigger PHP's memory limit.
        flush();
    }

    fclose($fp);
    

前端是直接只用的video标签;

在PC浏览器上是可以正常播放的,但是去到微信上就无法播放了,这个要怎么解决?求指教!

巴扎黑
巴扎黑

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号