tengo un SWF que carga unos videos de youtube por medio de un XML y un PHP llamado: PHP Youtube Downloader 2.0
lo hice basado en este tutorial:
Código :
http://www.leobaraldi.com.ar/2009/12/incluir-videos-de-youtube-en-tu-swf-descagar-video-youtube-con-flash-lista-personalizada-de-videos-youtube-en-flash-2/
la cosa es que no carga el video ni en local ni en el servidor
este es el XML:
Código XML :
<?xml version="1.0" encoding="utf-8"?> <VIDEOS volumen="100"> <video id="Mp251GQE-lI" titulo="El unico que sirve"> <![CDATA[este video si se ve]]> </video> <video id="GF4qad2sj00" titulo="Capusotto"> <![CDATA[Me encanta este video!]]> </video> <video id="6qEcX01WrNk" titulo="Previa de Soda en Cba"> <![CDATA[Se presento soda y fue toda una fiesta, impresionante!]]> </video> <video id="do1dAX-IVTE" titulo="El bananero - Harry Potter"> <![CDATA[Aca un video para morirse de risa del amigo elbananero]]> </video> <video id="qAWFk63Lrmw" titulo="Battlefield 2142 U2"> <![CDATA[Este un video que lo puse porque si nomas no tenia ganas de buscar ni de escribir]]> </video> </VIDEOS>
Este es el PHP:
Código PHP :
<?php
// File: phpyoutube.php
// Version: 2.2
// Date: 06/04/2009
// Web: http://blog.unijimpe.net
function getContent($url) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();
ob_end_clean();
return $string;
}
function fetch_headers($url) {
$headers = array();
$url = trim($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_NOBODY ,1);
$data = curl_exec($ch);
$errormsg = curl_error($ch);
curl_close($ch);
$headers = explode("\n", $data);
return $headers;
}
function getYoutubeToken($id) {
$path = "http://www.youtube.com/get_video_info?";
$cont = getContent($path."&video_id=".$id);
parse_str($cont, $opts);
return $opts['token'];
}
$videoItem = trim($_GET['item']);
$videoType = "";
$videoPath = "http://www.youtube.com/get_video";
if ($_GET['type'] != "0") {
$videoType = "&fmt=".$_GET['type'];
}
if ($videoItem != "") {
$videoTokn = getYoutubeToken($videoItem);
$videoURL = $videoPath."?video_id=".$videoItem."&t=".$videoTokn.$videoType;
$headers = fetch_headers($videoURL);
for ($i=0; $i<count($headers); $i++) {
if (strstr($headers[$i], "ocation:")) {
$str1 = explode("ocation:", $headers[$i]);
$link = trim($str1[1]);
break;
}
}
//header("Location: ".$link);
echo "video=".$link;
exit;
}
?>
y este es el Actionscript:
Código ActionScript :
//Dominio donde esta alojado nuestro php
var dominio:String = "";
//nuestro php propiamente dicho
var FilePHP:String = "phpyoutube.php";
//nuestro xml con la lista de videos
var FileXML:String = "videos.xml";
//el valor de id del video en youtube
var id:String = "";
//
var contador:Number = 0;
//
var miXML:XML = new XML();
miXML.ignoreWhite = true;
//
var ListVideos:Array = new Array();
miXML.onLoad = function(ok) {
if (ok) {
ListVideos = this.firstChild.childNodes;
cantVideos_txt.text = "total videos: "+String(ListVideos.length);
id = ListVideos[0].attributes.id;
cargarVideo();
loadDtaVdo();
//
} else {
}
};
miXML.load(dominio+FileXML);
//aca recibimos el resultado del php
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
/*********************************************/
//desde aqui el cambio realizado para el 08-10-2009
var varsTemp:LoadVars = new LoadVars()
varsTemp.decode(String(this))
var urlText:String = varsTemp.toString()
urlText = urlText.substr(35,urlText.length)
urlText = urlText.split('%2C').join(',');
urlText = urlText.split('%2E').join('.');
urlText = urlText.split('%2F').join('/');
urlText = urlText.split('%3F').join('?');
urlText = urlText.split('%3D').join('=');
urlText = urlText.split('%3A').join(':');
my_ns.play(urlText);
//hasta aqui el cambio realizado para el 08-10-2009
} else {
trace("Error connecting to server.");
}
};
//enviamos los datos al php
var send_lv:LoadVars = new LoadVars();
function cargarVideo() {
status_txt._visible = true;
status_txt.text = "cargando...";
send_lv.item = id;
send_lv.type = 0;
send_lv.sendAndLoad(dominio+FilePHP,result_lv,"GET");
}
//el encargado de cargar y reproducir el video
var my_video:Video;
var my_nc:NetConnection = new NetConnection();
my_nc.connect(null);
var my_ns:NetStream = new NetStream(my_nc);
my_video.attachVideo(my_ns);
//suavizado del video
my_video.smoothing = true;
//duracion del buffer
my_ns.setBufferTime(4);
//duracion del video
my_ns.onMetaData = function(infoObject:Object) {
//trace(Math.floor(infoObject.duration));
};
//enviamos datos de que esta sucediendo
my_ns.onStatus = function(infoObject:Object) {
if (infoObject.code == "NetStream.Buffer.Full") {
status_txt._visible = false;
}
if (infoObject.code == "NetStream.Play.Start") {
status_txt._visible = true;
buffer();
}
if (infoObject.code == "NetStream.Play.Stop") {
status_txt.text = "Video finalizado!";
}
if (infoObject.code == "NetStream.Play.StreamNotFound") {
status_txt.text = "No se encontro el video!!!";
}
};
//con esto sabemos si ya esta el buffer listo!
function buffer() {
this.onEnterFrame = function() {
var porcentaje:Number = Math.min(Math.round(my_ns.bufferLength/my_ns.bufferTime*100), 100);
status_txt.text = "Buffer:"+porcentaje+"%";
if (porcentaje == 100) {
delete this.onEnterFrame;
}
};
}
//un efectito fade
MovieClip.prototype.fade = function(direccion:String, velocidad:Number) {
if (direccion == "in") {
var efecto = mx.transitions.easing.Regular.easeIn;
this.mi_Tween = new mx.transitions.Tween(this, '_alpha', efecto, this._alpha, 100, velocidad, true);
} else {
var efecto = mx.transitions.easing.Regular.easeOut;
this.mi_Tween = new mx.transitions.Tween(this, '_alpha', efecto, this._alpha, 0, velocidad, true);
}
};
//creamos la funcionalidad de los botones y cargamos los datos de la info
function loadDtaVdo() {
for (var i = 0; i<2; i++) {
this["video"+i].fdoFicha_mc._alpha = 0;
this["video"+i]._alpha = 0;
this["video"+i].fade("in",0.5);
var temp = this["video"+i].fdoFicha_mc;
this["video"+i].reproducir_mc.fondo = temp;
this["video"+i].mini_mc.loadMovie("http://img.youtube.com/vi/"+ListVideos[contador].attributes.id+"/1.jpg");
this["video"+i].titulo_txt.text = ListVideos[contador].attributes.titulo;
this["video"+i].descripcion_txt.text = ListVideos[contador].firstChild;
//
this["video"+i].reproducir_mc.id = ListVideos[contador].attributes.id;
this["video"+i].reproducir_mc.onRelease = function() {
video0.fdoFicha_mc._alpha = 0;
video1.fdoFicha_mc._alpha = 0;
this.fondo.fade("in",0.5);
id = this.id;
cargarVideo();
//
};
if (this["video"+i].reproducir_mc.id == id) {
this["video"+i].fdoFicha_mc.fade("in",0.5);
}
if (contador == ListVideos.length-1) {
contador = 0;
} else {
contador++;
}
}
}
//accion boton siguiente
siguiente_btn.onRelease = function() {
loadDtaVdo();
};
//
aca tengo colgado el proyecto:
Código :
http://pruebita.net84.net/
agradezco si me pueden colaborar
