mediaelement.js从php加载视频

时间:2012-06-29 07:56:34

标签: mediaelement.js

我正在尝试使用mediaelement.js加载来自php的视频,但它无效..它显示“下载文件”

<video src="http://localhost/readmp4.php?id=111" width="640" height="360" id="player2" controls="controls">
<source type="video/mp4" src="http://localhost/readmp4.php?id=111" />
</video>
<script>
$('video').mediaelementplayer({});
</script>

2 个答案:

答案 0 :(得分:1)

我花了1.5小时来解决为什么mediaelement没有播放从php返回的音频文件。 darleys的建议有效,但是添加type =“audio / mpeg”也使它有效。

<audio src="stream.php?file=<?php echo urlencode($abs_file);?>" type="audio/mpeg" />

答案 1 :(得分:-2)

  1. 确保将mp4伪装成路径而不是php请求网址 例如<video src=/junk/junk.mp4> instead of <video src=video.php?name=junk>

  2. 执行到php文件的htaccess路由,当用户请求一个路径路由到一个php文件,该文件将读取位置中保护的视频文件。  例如......

  3.   

    RewriteRule ^ junk /(.*)/preview.php?media=$1 [QSA,L]

    1. 现在在php中,一定要满足safari(ipad / iphone)的要求......

      <?php
      class VideoGroup1 {
         public function preview() { 
             $id = substr($_REQUEST['media'],0,strrpos($_REQUEST['media'],"."));
             $thisMedia = Pillar_Manage_Media::fetchMedia($id);
             //echo Foundry_Useful::unsealit($thisMedia['path']).$thisMedia['mediaid'];
             $file = Foundry_Useful::unsealit($thisMedia['path']).$thisMedia['mediaid'].".mp4";
             $filesize = filesize($file);
      
             $offset = 0;
             $length = $filesize;
      
             if ( isset($_SERVER['HTTP_RANGE']) ) {
      
      
                 $partialContent = true;
      
      
                 preg_match('/bytes=(\d+)-(\d+)?/', $_SERVER['HTTP_RANGE'], $matches);
      
                 $offset = intval($matches[1]);
                 $length = intval($matches[2]) - $offset;
             } else {
                 $partialContent = false;
             }
      
             $file = fopen($file, 'r');
      
      
             fseek($file, $offset);
      
             $data = fread($file, $length);
      
             fclose($file);
      
             if ( $partialContent ) {
      
      
                 header('HTTP/1.1 206 Partial Content');
      
                 header('Content-Range: bytes ' . $offset . '-' . ($offset + $length) . '/' . $filesize);
             }
      
      
             header('Content-Type: video/mp4');
             header('Content-Length: ' . $filesize);
             header('Content-Disposition: attachment; filename="' . $file . '"');
             header('Accept-Ranges: bytes');
      
             print($data);
      
         }//End Function preview
      
      
      }//END Class VideoGroup1