-
//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();
-
};
-
//
16th Marzo, 2010 at 7:02 pm
Cordial Saludo Leobaraldi.
Esta muy bueno este tutorial.
De casualidad usted sabe como hacer para crear un reproductor de videos de flash en actionscript 3 que se actualice automaticamente con los videos que se publican en un canal de youtube??..
Saludos.
Juan Jose
24th Marzo, 2010 at 7:58 pm
el tutorial esta buenazo pero.....no carga el video
6th Abril, 2010 at 6:44 pm
Leobardi; se a caido de nuevo el reproductor!
21st Junio, 2010 at 10:37 am
Hola, buenisimo el tutorial.. pero el video no carga.. solo se cargan las imagenes en miniatura de los video... xD
13th Julio, 2010 at 1:08 pm
No carga los videos solo las imagenes en pequeño, podrias arreglarlo y te estaria inmensamente agradecido. Saludos desde Monterrey mexico.
28th Julio, 2010 at 4:57 pm
hola! muy bien explicado el tutorial, lo que pasa que no carga los vídeos... de que depende eso?
gracias!