我正在尝试直接播放位于远程服务器上的视频(本例中为www.nowvideo.eu),使用curl()和preg_match()获取视频直接URL,然后使用找到的下载脚本{ {3}}直接将.php文件显示为视频文件本身。
下载视频有效,但是当我尝试将一个参数'file = video_file.php'添加到jwplayer时,我收到此错误:“ 任务队列在步骤5失败:无法加载播放列表跨域政策限制。 “ 我有一个crossdomain.xml文件,它设置为允许从所有域访问,但我不知道为什么它甚至很重要因为video_file.php与play.php在同一个域中(包含jw播放器代码)。
以下是 video_file.php 的代码:
<?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 的代码(位于root上):
<?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>
有什么想法吗?
答案 0 :(得分:1)
变化:
&安培;拉伸= exactfit
要:
&安培;拉伸= exactfit&安培;提供商=视频
现在,这将在JW播放器中工作(我假设你在这里使用JW5)。
-Ethan