2014-07-06 2 views
2

mp4 파일에 문제가 있습니다. Html5 비디오 태그는 직접 링크로 재생할 수 있지만 PHP 헤더로는 재생할 수 없습니다 (Mp3은 PHP 헤더로 잘 작동 함). 나는 거의 스택 솔루션의 시도하지만 여전히 내 문제를 :(해결되지 않은Chrome에서 HTML5 동영상 태그의 PHP를 통해 mp4 파일을 재생 하시겠습니까?

듣고 내 코드입니다 :

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> 

이유를 모르겠다. (도와주세요.

고마워,

답변

5

OK! 나는 그것을 시도하고 아직도 한 답변 : 대한

$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; 
} 
2

나는 당신이 당신의 PHP 파일에 불필요한 헤더를 추가했다고 생각한다. 이 하나를 시도

$local_file = 'z.mp4'; 
$size = filesize($local_file); 

header("Content-Type: video/mp4"); 
header("Content-Length: ".$size); 

readfile($local_file); 

그리고이

<video width="480" height="320" controls> 
    <source src="mp4.php" type="video/mp4"> 
</video> 

편집과 같은 HTML 코드 뭔가 :이를 당신의 Content-Type 헤더와 HTML 비디오 유형을 변경하는 경우도 MP3 파일을 작동합니다.

<video width="480" height="320" controls> 
    <source src="mp3.php" type="audio/mpeg"> 
</video> 
+0

감사합니다 : 내 문제는 내가

그냥 그 코드를 사용할 때이 사람이 같은 문제가 도움이되기를 바랍니다 :) 해결했습니다 작동 : (mp3.php 및 직접 링크 (mp3 및 mp4 모두) 제대로 작동하지만 mp4.php는 –

+0

이 아닙니다. mp4 파일에 문제가있을 수 있습니다. 다른 파일을 시도한 적이 있습니까? –

+0

예, 다른 파일을 시도했습니다. 그들은 또한 작동하지 않았다 :) –

관련 문제