使用php播放大尺寸的视频 [英] playing video of large size using php

查看:484
本文介绍了使用php播放大尺寸的视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面有代码可以通过php播放视频

i had code below to play video through php

<?php

        /*$file = "d.mp4";
        $file_size = filesize($file);
        $fp = fopen($file, "rb");
        $data = fread ($fp, $file_size);
        fclose($fp);
        header ("Content-type: video/mp4");
        echo $data; */

 $path = 'f.mp4';
 if (file_exists($path))
 {
 $size=filesize($path);
 $fm=@fopen($path,'rb');
 $begin=0;
 $end=$size;
 if(isset($_SERVER['HTTP_RANGE'])) {
    if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i',
        $_SERVER['HTTP_RANGE'],$matches)){
        $begin=intval($matches[0]);
        if(!empty($matches[1])) {
            $end=intval($matches[1]);
        }
    }
 }
 if($begin>0||$end<$size)
     header('HTTP/1.0 206 Partial Content');
 else
     header('HTTP/1.0 200 OK');
     header("Content-Type: video/mp4");
     header('Accept-Ranges: bytes');
     header('Content-Length:'.($end-$begin));
     header("Content-Disposition: inline;");
     header("Content-Range: bytes $begin-$end/$size");
     header("Content-Transfer-Encoding: binary\n");
     header('Connection: close');
     $cur=$begin;
     fseek($fm,$begin,0);
     while(!feof($fm)&&$cur<$end&&(connection_status()==0))
         {
        print fread($fm,min(1024*16,$end-$cur));
        $cur+=1024*16;
        usleep(1000);
     }
     die();
 }

    ?>




但是问题是启动视频需要花费几秒钟,并且用户不断单击播放按钮.

想要的是应该有加载之类的东西,以便用户可以理解vidoe正在像您的电子管一样加载.

请帮忙.




but problem is that it takes few seconds to start vidoe, and user keeps on clicking play button.

What is want is something like loading should be there so that user may understand that vidoe is loading like you tube.

Please help.

推荐答案

file ="d.mp4";
file = "d.mp4";


file_size = filesize(
file_size = filesize(


文件);


这篇关于使用php播放大尺寸的视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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