Foros del Web » Creando para Internet » Flash y Actionscript »

Videos en XML AS 2 <help>

Estas en el tema de Videos en XML AS 2 <help> en el foro de Flash y Actionscript en Foros del Web. Amigos una consulta miren tengo el siguiente código que hace se reproduzcan varios vídeos uno a continuación del otro sin pausas y necesito vuestra ayuda.. ...
  #1 (permalink)  
Antiguo 25/02/2010, 15:10
 
Fecha de Ingreso: diciembre-2009
Mensajes: 24
Antigüedad: 14 años, 4 meses
Puntos: 1
Pregunta Videos en XML AS 2 <help>

Amigos una consulta miren tengo el siguiente código que hace se reproduzcan varios vídeos uno a continuación del otro sin pausas y necesito vuestra ayuda..

en el siguiente codigo debe haber un numero que este especificando el mínimo necesario de carga (sea Kb o MB) para comenzar a reproducir los videos y que al ser reproducidos no se vean pausas y la reproduccion sea fluida sin pausas, *obviamente mientras mas carga al inicio pueden reproducirse sin problemas ó me equivoco.

url en accion:
[URL="http://www.idclogic-proyectos.com/videopostales.pe/video-player/video-player.html"]http://www.idclogic-proyectos.com/videopostales.pe/video-player/video-player.html[/URL]

código Actionscript
Código actionscript:
Ver original
  1. stop();
  2. //---------------------  Variables ------------------------//
  3. var nDownload:Number;
  4. var nPlayback:Number;
  5. var totalLength:Number;
  6. //total length(in secs) of movie playing
  7. var currentVideo:Number = 0;
  8. var totalVideos:Number;
  9. var scrubSpeed:Number = 2;
  10. //scrubbing speed when scrub buttons are pressed
  11. var paused:Boolean = false;
  12. //whether movie is paused or not
  13. var movieEnded:Boolean;
  14. var aVideos:Array = new Array();
  15. //boton repetir
  16. btn_repetir._visible=false;
  17.  
  18. // ---------------------- Carga XML -----------------------//
  19. var videoXML:XML = new XML();
  20. videoXML.ignoreWhite = true;
  21. var rootNode:XMLNode;
  22. var currNode:XMLNode;
  23. videoXML.onLoad = function():Void  {
  24.     rootNode = this.firstChild;
  25.     for (var i:Number = 0; i<rootNode.childNodes.length; i++) {
  26.         currNode = rootNode.childNodes[i];
  27.         aVideos.push({source:currNode.attributes["source"], title:currNode.attributes["title"], author:currNode.attributes["author"], year:currNode.attributes["year"]});
  28.     }
  29.     totalVideos = aVideos.length;
  30.     populateList();
  31. };
  32. videoXML.load("videos.php");
  33.  
  34. //------------------------------List Box and Fields-------------------------------//
  35. var cList:Object = mcTab.mcPlaylist.cList;
  36. cList.vScrollPolicy = "auto";
  37. var listListener:Object = new Object();
  38. cList.addEventListener("change", listListener);
  39. listListener.change = function() {
  40.     var index:Number = cList.selectedIndex;
  41.     currentVideo = index;
  42.     populateFields(index);
  43.     playVideo(aVideos[index].source);
  44. };
  45. function populateList():Void {
  46.     for (var i:Number = 0; i<totalVideos; i++) {
  47.         cList.addItem(aVideos[i].title);
  48.     }
  49.     cList.selectedIndex = currentVideo;
  50.     populateFields(0);
  51.     playVideo(aVideos[0].source);
  52. }
  53. function populateFields(index:Number):Void {
  54.     tTitle.text = aVideos[index].title;
  55.     tYear.text = aVideos[index].year;
  56.     tAuthor.text = aVideos[index].author;
  57. }
  58. // ---------------- NetConnection and NetStream Objects --------------//
  59. var nc:NetConnection = new NetConnection();
  60. nc.connect(null);
  61. var ns:NetStream = new NetStream(nc);
  62. ns.setBufferTime(2);
  63. mcVideo.oVideo.attachVideo(ns);
  64. function playVideo(video:String):Void {
  65.     movieEnded = false;
  66.     mcBuffer._visible = true;
  67.     clearIntervals();
  68.     ns.play(video);
  69.     nDownload = setInterval(downloadProgress, 1000/24);
  70.     nPlayback = setInterval(playback, 1000/24);
  71. }
  72. //-----------------------------------onStatus Event Handlers -------------------//
  73. ns.onStatus = function(oInfo:Object):Void  {
  74.     trace(oInfo.code);
  75.     if (oInfo.code == "NetStream.Play.Start") {
  76.         trace("movie has started");
  77.     }
  78.     if (oInfo.code == "NetStream.Play.Stop") {
  79.         //trace("stop");       
  80.         clearInterval(nPlayback);
  81.         movieEnded = true;
  82.         mcBuffer._visible = false;
  83.        
  84.     }
  85.     if (oInfo.code == "NetStream.Play.StreamNotFound") {
  86.         //trace("movie cannot be found");
  87.     }
  88.     if (oInfo.code == "NetStream.Buffer.Full") {
  89.         mcBuffer._visible = false;
  90.     }
  91.     if (oInfo.code == "NetStream.Buffer.Empty" && !movieEnded) {
  92.         //trace("buffer empty");
  93.         mcBuffer._visible = true;
  94.         //buffer is empty now we need to check if remaining movie time is less buffer requirement
  95.         var timeRemaining:Number = totalLength-ns.time;
  96.         if (int(totalLength)> Math.ceil(ns.time)) {
  97.             ns.setBufferTime(timeRemaining);
  98.         } else { // go to next movie
  99.             mcControls.mcNext.onRelease()
  100.         }
  101.     }
  102. };
  103. ns["onMetaData"] = function (oInfo:Object):Void {
  104.     totalLength = oInfo.duration;
  105. };
  106. //-----------------------------   Download Progress --------------------//
  107. var nBytesLoaded:Number;
  108. var nBytesTotal:Number;
  109. var percentageLoaded:Number;
  110. function downloadProgress():Void {
  111.     nBytesLoaded = ns.bytesLoaded;
  112.     nBytesTotal = ns.bytesTotal;
  113.     percentageLoaded = nBytesLoaded/nBytesTotal*100;
  114.     mcProgressBar.mcDownloadBar._xscale = percentageLoaded;
  115.     if (percentageLoaded == 100) {
  116.         clearInterval(nDownload);
  117.     }
  118. }
  119. //----------------------------------------PLAYBACk PROGRESS ----------------------------------//
  120. var percentPlayed:Number;
  121. function playback():Void {
  122.     percentPlayed = ns.time/totalLength*100;
  123.     tTime.text = (totalLength) ? convertToTime(ns.time, true)+" / "+convertToTime(totalLength) : convertToTime(ns.time, true);
  124.     mcProgressBar.mcPlayhead._x = percentPlayed*1.5;
  125. }
  126. /**
  127. * Helper function to display time based on seconds
  128. * @param secs:Numbers, seconds to convert
  129. * @return String, formated time
  130. */
  131. function convertToTime(secs:Number, round:Boolean):String {
  132.     if(round) secs = Math.ceil(secs)
  133.     var min = int(secs/60);
  134.     if (min<10) {
  135.         min = "0"+min;
  136.     } else if (min>59) {
  137.         //add hours if neccesary
  138.         min = min%60;
  139.         var hours = int(min/60);
  140.         if (hours<10) {
  141.             hours = "0"+hours;
  142.         }
  143.         if (min<10) {
  144.             min = "0"+min;
  145.         }
  146.     }
  147.     var segs = int(((secs%60)*100)/100);
  148.     if (segs<10) {
  149.         segs = "0"+segs;
  150.     }
  151.     return (hours) ? hours+":"+min+":"+segs : min+":"+segs;
  152. }
  153. //-------------------------- Playback controls and Scrub-------------------//
  154. mcControls.mcPlay.onRelease = function():Void  {
  155.     if (paused) {
  156.         ns.pause();
  157.         paused = !paused;
  158.     }
  159. };
  160. mcControls.mcNext.onRelease = function():Void  {
  161.     currentVideo++;
  162.     if (currentVideo == totalVideos) {
  163.         //currentVideo = 0;
  164.     //---------------BOTON REPETIR----------------//
  165.         btn_repetir._visible=true;
  166.         btn_repetir.onRelease=function(){
  167.             //funcion para reproducir de nuevo
  168.             gotoAndPlay(1);
  169.             }
  170.     }
  171.     cList.selectedIndex = currentVideo;
  172.     populateFields(currentVideo);
  173.     playVideo(aVideos[currentVideo].source);
  174. };
  175. mcControls.mcPrevious.onRelease = function():Void  {
  176.     currentVideo--;
  177.     if (currentVideo<0) {
  178.         currentVideo = totalVideos-1;
  179.     }
  180.     cList.selectedIndex = currentVideo;
  181.     populateFields(currentVideo);
  182.     playVideo(aVideos[currentVideo].source);
  183. };
  184. mcControls.mcForward.onPress = function():Void  {
  185.     this.onEnterFrame = function():Void  {
  186.         ns.seek(ns.time+scrubSpeed);
  187.     };
  188. };
  189. mcControls.mcForward.onRelease = function():Void  {
  190.     delete this.onEnterFrame;
  191. };
  192. mcControls.mcRewind.onPress = function():Void  {
  193.     this.onEnterFrame = function():Void  {
  194.         ns.seek(ns.time-scrubSpeed);
  195.     };
  196. };
  197. mcControls.mcRewind.onRelease = function():Void  {
  198.     delete this.onEnterFrame;
  199. };
  200. mcControls.mcPause.onRelease = function():Void  {
  201.     ns.pause();
  202.     paused = !paused;
  203. };
  204. mcProgressBar.mcPlayhead.onPress = function():Void  {
  205.     clearInterval(nPlayback);
  206.     this.startDrag(true, 0, this._y, mcProgressBar.mcDownloadBar._xscale*1.5, this._y);
  207.     this.onEnterFrame = function():Void  {
  208.         ns.seek(this._x*totalLength/150);
  209.     };
  210. };
  211. mcProgressBar.mcPlayhead.onRelease = function():Void  {
  212.     this.stopDrag();
  213.     delete this.onEnterFrame;
  214.     nPlayback = setInterval(playback, 1000/24);
  215. };
  216. mcProgressBar.mcPlayhead.onReleaseOutside = mcProgressBar.mcPlayhead.onRelease;
  217.  
  218. //-------------------------- MUTE BUTTON ----------------------------------------------------//
  219. var flvSound_mc:MovieClip = _root.createEmptyMovieClip("flvSound_mc", _root.getNextHighestDepth());
  220. flvSound_mc.attachAudio(ns);
  221. var soundHolder_sound:Sound = new Sound(flvSound_mc);
  222. soundHolder_sound.setVolume(100);
  223. mcMute.onRelease = function():Void  {
  224.     if (soundHolder_sound.getVolume() == 100) {
  225.         soundHolder_sound.setVolume(0);
  226.         mcMute.gotoAndStop(2);
  227.     } else {
  228.         soundHolder_sound.setVolume(100);
  229.         mcMute.gotoAndStop(1);
  230.     }
  231. };
  232. //-----------------------------------TOOL TIPs For controls--------------------------------------------//
  233. mcTip.tText.autoSize = "left";
  234. mcControls.mcPlay.onRollOver = toolTip;
  235. mcControls.mcForward.onRollOver = toolTip;
  236. mcControls.mcRewind.onRollOver = toolTip;
  237. mcControls.mcNext.onRollOver = toolTip;
  238. mcControls.mcPrevious.onRollOver = toolTip;
  239. mcControls.mcPause.onRollOver = toolTip;
  240. mcControls.mcPlay.onRollOut = resetTip;
  241. mcControls.mcRewind.onRollOut = resetTip;
  242. mcControls.mcForward.onRollOut = resetTip;
  243. mcControls.mcNext.onRollOut = resetTip;
  244. mcControls.mcPrevious.onRollOut = resetTip;
  245. mcControls.mcPause.onRollOut = resetTip;
  246. mcControls.mcPlay.onRollOut = resetTip;
  247. function toolTip():Void {
  248.     switch (this) {
  249.     case _level0.mcControls.mcNext :
  250.         mcTip.tTip.text = "next";
  251.         break;
  252.     case _level0.mcControls.mcPrevious :
  253.         mcTip.tTip.text = "previous";
  254.         break;
  255.     case _level0.mcControls.mcForward :
  256.         mcTip.tTip.text = "forward";
  257.         break;
  258.     case _level0.mcControls.mcRewind :
  259.         mcTip.tTip.text = "rewind";
  260.         break;
  261.     case _level0.mcControls.mcPlay :
  262.         mcTip.tTip.text = "play";
  263.         break;
  264.     case _level0.mcControls.mcPause :
  265.         mcTip.tTip.text = "pause";
  266.         break;
  267.     }
  268.     this.onEnterFrame = function():Void  {
  269.         mcTip._x = _xmouse;
  270.     };
  271. }
  272. function resetTip():Void {
  273.     delete this.onEnterFrame;
  274.     mcTip.tTip.text = "";
  275. }
  276. //-------------------------PLAYLIST TAB FUNCTIONALITY ----//
  277. mcTab.mcHit.onRollOver = function():Void  {
  278.     mcTab.play();
  279. };
  280. //-----------------------------clear intervals ---------------------//
  281. function clearIntervals():Void {
  282.     clearInterval(nDownload);
  283.     clearInterval(nPlayback);
  284. }

Última edición por ainterfaces; 25/02/2010 a las 15:42 Razón: mejorar la lectura del código

Etiquetas: xml, video
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:14.