Pass video-Datei von einem remote-URL zu jwplayer mit PHP als 'file=' parameter

Ich versuche, direkt ein video Abspielen, die sich auf remote-server (www.nowvideo.eu in diesem Beispiel), erhalten video die direkte URL mit curl() und preg_match(), und verwenden Sie dann den download-Skript gefunden hier direkt, dass .php-Datei als video-Datei selbst.

Video herunterladen funktioniert, aber wenn ich versuche, fügen Sie ein param 'file=video_file.php' zu jwplayer ich bekomme diese Fehlermeldung: "Aufgabe Warteschlange nicht bei Schritt 5: Playlist konnte nicht geladen werden aufgrund crossdomain policy restrictions."
Ich habe einen crossdomain.xml Datei, es ist eingestellt, dass der Zugriff von allen Domänen aus, aber ich weiß nicht, warum ist es überhaupt wichtig, da video_file.php ist auf der gleichen Domäne wie play.php (mit dem jw player-code).

Hier ist der code für 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);
}
?>

Hier ist der code für 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 für crossdomain.xml (auf 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>

Irgendwelche Ideen?

InformationsquelleAutor Augustus | 2013-03-02
Schreibe einen Kommentar