2013-03-02 1 views
2

원격 서버 (이 예에서는 www.nowvideo.eu)에있는 비디오를 직접 재생하려고 시도하고 있습니다. curl() 및 preg_match()를 실행 한 다음 다운로드 스크립트를 사용하여 here이 .php 파일을 직접 비디오 파일 자체로 표시합니다.'file ='매개 변수로 PHP를 사용하여 원격 URL에서 jwplayer로 패스

비디오가 작동 다운로드,하지만 난 PARAM 추가하려고하면 '파일을 = video_file.php은'나는이 오류를 얻을 jwplayer하기 : 인해 도메인 간 정책 제한에 재생 목록을로드 할 수 없습니다 : "작업 대기열 5 단계에서 실패를 . " 나는 모든 도메인에서 액세스 할 수 있도록 설정된 crossdomain.xml 파일이 있지만, 왜 video_file.php는 play.php와 동일한 도메인에 있으므로이 파일이 중요한지 잘 모릅니다. jw 플레이어 코드). 여기

<?php 
$url = 'http://www.nowvideo.eu/video/qdu0vx7m3m3xd'; 
$content = curl($url); 
preg_match('%video/(.[^/]*+)%', $url, $videoID); 
preg_match('/filekey="(.[^\"]*?)"/',$content,$key); 
$key = str_replace('"','',$key[0]); 
$video_data = 'http://www.nowvideo.eu/api/player.api.php?user=undefined&pass=undefined&file='.$videoID[1].'&key='.$key; 
$content_key = curl($video_data); 
preg_match('/url=(.[^&]*+)/',$content_key,$file); 
$file = str_replace('url=','',$file[0]); 
download($file,2000); 

/* 
Set Headers 
Get total size of file 
Then loop through the total size incrementing a chunck size 
*/ 
function download($file,$chunks){ 
    set_time_limit(0); 
    header('Content-Description: File Transfer'); 
    header('Content-Type: video/x-flv'); 
    header('Content-disposition: inline; filename='.basename($file)); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header('Expires: 0'); 
    header('Pragma: public'); 
    $size = get_size($file); 
    header('Content-Length: '.$size); 

    $i = 0; 
    while($i<=$size){ 
     //Output the chunk 
     get_chunk($file,(($i==0)?$i:$i+1),((($i+$chunks)>$size)?$size:$i+$chunks)); 
     $i = ($i+$chunks); 
    } 

} 

function curl($url){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $result = curl_exec($ch); 
    curl_close($ch); 
return $result; 
} 

//Callback function for CURLOPT_WRITEFUNCTION, This is what prints the chunk 
function chunk($ch, $str) { 
    print($str); 
    return strlen($str); 
} 

//Function to get a range of bytes from the remote file 
function get_chunk($file,$start,$end){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $file); 
    curl_setopt($ch, CURLOPT_RANGE, $start.'-'.$end); 
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'chunk'); 
    $result = curl_exec($ch); 
    curl_close($ch); 
} 

//Get total size of file 
function get_size($url){ 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_NOBODY, true); 
    curl_exec($ch); 
    $size = curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD); 
    return intval($size); 
} 
?> 

play.php 코드입니다 :

<html> 
<head> 
</head> 
<body> 
<object id="flashplayer" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="830" height="490"> 
<param name="movie" value="http://example.com/player.swf"> 
<param name="allowFullScreen" value="true"> 
<param name="allowScriptAccess" value="always"> 
<param name="FlashVars" value="file=http://example.com/video_file.php&autostart=true&smoothing=true&stretching=exactfit"> 
<embed name="flashplayer" src="http://example.com/player.swf" flashvars="file=http://example.com/video_file.php&autostart=true&smoothing=true&stretching=exactfit" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="830" height="490"> 
</object> 
</body> 
</html> 

코드에 crossdomain.xml에 대한 (에 위치한 여기

video_file.php 코드입니다 루트) :

<?xml version="1.0"?> 
<!DOCTYPE cross-domain-policy SYSTEM 
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> 
<cross-domain-policy> 
<allow-access-from domain="*" secure="false"/> 
<allow-http-request-headers-from domain="*" headers="*" secure="false"/> 
</cross-domain-policy> 

아이디어가 있으십니까?

답변

1

변경 : 나는 가정하고 (스트레칭 =이 JW Player에서, & 제공 = 이제

, 이것은 작동 비디오를 exactfit

& :

& 스트레칭 =이

에 exactfit 여기에서 JW5를 사용하고 있습니다).

-Ethan

+0

감사합니다. :) – Augustus

+0

굉장, 문제 없습니다! :-) – emaxsaun

+0

나는 쿼리 문자열 매개 변수가있는 URL을 전달하고 있는데 문제는 인코딩 된 URL이라고 생각했지만이 공급자 매개 변수로 내 문제를 해결했습니다! 정말 고마워! –

관련 문제