2012-06-29 31 views
0

加載視頻我試圖加載從PHP視頻,使用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
  1. 確保僞裝一個MP4的路徑,而不是一個PHP請求URL 例如<video src=/junk/junk.mp4> instead of <video src=video.php?name=junk>

  2. 做htaccess的路線到PHP文件,當用戶請求的路徑路由到一個PHP文件,該文件是要讀取視頻文件在一個位置安全。 例如...

重寫規則^垃圾/(.*)/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 
    
1

我花了1.5小時解決爲什麼mediaelement沒有播放從php返回的音頻文件。 darleys的建議工作,但也加入type =「audio/mpeg」也使它的工作。

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

+0