douxuanjie2692 2013-03-02 14:03
浏览 133
已采纳

使用PHP作为'file ='参数将视频文件从远程URL传递到jwplayer

I'm trying to directly play a video that is located on remote server (www.nowvideo.eu in this example), get video direct URL using curl() and preg_match(), and then using the download script found here directly present that .php file as the video file itself.

Downloading video works, but when I try to add a param 'file=video_file.php' to jwplayer I get this error: "Task Queue failed at step 5: Playlist could not be loaded due to crossdomain policy restrictions." I have a crossdomain.xml file, it is set to allow access from all domains, but I don't know why is it even important since video_file.php is on the same domain as play.php (which contains jw player code).

Here is the code for 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);
}
?>

Here is the code for 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>

Code for crossdomain.xml (located on 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>

Any ideas?

展开全部

  • 写回答

1条回答 默认 最新

  • douzhao9608 2013-03-02 14:55
    关注

    Change:

    &stretching=exactfit

    To:

    &stretching=exactfit&provider=video

    Now, this will work, in the JW Player (I am assuming you are using JW5 here).

    -Ethan

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
  • ¥15 FastReport 怎么实现打印后马上关闭打印预览窗口
  • ¥15 利用3支股票数据估计其均值和方差的95%置信区间。
  • ¥15 微信小程序运行一项功能时,弹出未知错误弹框,检查代码没有问题
  • ¥15 ATAC测序生成self-pseudo replicates之前是否要进行去线粒体reads
  • ¥15 python模糊字匹配函数问题
  • ¥20 谁刷目标页面的uv记录器上数据,数据只记录跳转的数值
  • ¥30 数据库软件的安装方法
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部