douxuanjie2692 2013-03-02 22: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 22: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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器