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

Frenar reproduccion de video

Estas en el tema de Frenar reproduccion de video en el foro de Flash y Actionscript en Foros del Web. Hola gente, Tengo un componente de reproducción de videos que lee de un xml. Utiliza un buffer. El problema que tengo es que se inicia ...
  #1 (permalink)  
Antiguo 03/11/2008, 14:27
Avatar de Juanmax  
Fecha de Ingreso: diciembre-2005
Ubicación: Paraná, Entre Ríos , Argentina
Mensajes: 90
Antigüedad: 12 años
Puntos: 0
Exclamación Frenar reproduccion de video

Hola gente,
Tengo un componente de reproducción de videos que lee de un xml. Utiliza un buffer. El problema que tengo es que se inicia en reproducción el video y yo quiero que cargue el buffer sin reproducir, que lo haga al aretar el boton de play. Les dejo el código.

Código:
//---------------------  Variables ------------------------//
var nDownload:Number;
var nPlayback:Number;
var totalLength:Number;
//total length(in secs) of movie playing
var currentVideo:Number = 0;
var totalVideos:Number;
var scrubSpeed:Number = 5;
//scrubbing speed when scrub buttons are pressed
var paused:Boolean = false;
//whether movie is paused or not
var movieEnded:Boolean;
var aVideos:Array = new Array();
// ---------------------- Load XML -----------------------//
var videoXML:XML = new XML();
videoXML.ignoreWhite = true;
var rootNode:XMLNode;
var currNode:XMLNode;
videoXML.onLoad = function():Void  {
	rootNode = this.firstChild;
	for (var i:Number = 0; i<rootNode.childNodes.length; i++) {
		currNode = rootNode.childNodes[i];
		aVideos.push({source:currNode.attributes["source"], title:currNode.attributes["title"], author:currNode.attributes["author"], year:currNode.attributes["year"]});
	}
	totalVideos = aVideos.length;
	populateList();
};
videoXML.load("videos.xml");
//------------------------------List Box and Fields-------------------------------//
var cList:Object = mcTab.mcPlaylist.cList;
cList.vScrollPolicy = "auto";
var listListener:Object = new Object();
cList.addEventListener("change", listListener);
listListener.change = function() {
	var index:Number = cList.selectedIndex;
	currentVideo = index;
	populateFields(index);
	playVideo(aVideos[index].source);
};
function populateList():Void {
	for (var i:Number = 0; i<totalVideos; i++) {
		cList.addItem(aVideos[i].title);
	}
	cList.selectedIndex = currentVideo;
	populateFields(0);
	playVideo(aVideos[0].source);
}
function populateFields(index:Number):Void {
	tTitle.text = aVideos[index].title;
	tYear.text = aVideos[index].year;
	tAuthor.text = aVideos[index].author;
}
// ---------------- NetConnection and NetStream Objects --------------//
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.setBufferTime(5);
mcVideo.oVideo.attachVideo(ns);
function playVideo(video:String):Void {
	movieEnded = false;
	mcBuffer._visible = true;
	clearIntervals();
	ns.play(video);
	nDownload = setInterval(downloadProgress, 1000/24);
	nPlayback = setInterval(playback, 1000/24);
}
//-----------------------------------onStatus Event Handlers -------------------//
ns.onStatus = function(oInfo:Object):Void  {
	trace(oInfo.code);
	if (oInfo.code == "NetStream.Play.Start") {
		//trace("movie has started");
	}
	if (oInfo.code == "NetStream.Play.Stop") {
		//trace("movie ended");		
		clearInterval(nPlayback);
		movieEnded = true;
		mcBuffer._visible = false;
	}
	if (oInfo.code == "NetStream.Play.StreamNotFound") {
		//trace("movie cannot be found");
	}
	if (oInfo.code == "NetStream.Buffer.Full") {
		mcBuffer._visible = false;
	}
	if (oInfo.code == "NetStream.Buffer.Empty" && !movieEnded) {
		//trace("buffer empty");
		mcBuffer._visible = true;
		//buffer is empty now we need to check if remaining movie time is less buffer requirement
		var timeRemaining:Number = totalLength-ns.time;
		if (int(totalLength)>Math.ceil(ns.time)) {
			ns.setBufferTime(timeRemaining);
		} else { // go to next movie
			mcControls.mcNext.onRelease()
		}
	}
};
ns["onMetaData"] = function (oInfo:Object):Void {
	totalLength = oInfo.duration;
};
//-----------------------------   Download Progress --------------------//
var nBytesLoaded:Number;
var nBytesTotal:Number;
var percentageLoaded:Number;
function downloadProgress():Void {
	nBytesLoaded = ns.bytesLoaded;
	nBytesTotal = ns.bytesTotal;
	percentageLoaded = nBytesLoaded/nBytesTotal*100;
	mcProgressBar.mcDownloadBar._xscale = percentageLoaded;
	if (percentageLoaded == 100) {
		clearInterval(nDownload);
	}
}
//----------------------------------------PLAYBACk PROGRESS ----------------------------------//
var percentPlayed:Number;
function playback():Void {
	percentPlayed = ns.time/totalLength*100;
	tTime.text = (totalLength) ? convertToTime(ns.time, true)+" / "+convertToTime(totalLength) : convertToTime(ns.time, true);
	mcProgressBar.mcPlayhead._x = percentPlayed*1.5;
}
/**
* Helper function to display time based on seconds
* @param secs:Numbers, seconds to convert
* @return String, formated time
*/
function convertToTime(secs:Number, round:Boolean):String {
	if(round) secs = Math.ceil(secs)
	var min = int(secs/60);
	if (min<10) {
		min = "0"+min;
	} else if (min>59) {
		//add hours if neccesary
		min = min%60;
		var hours = int(min/60);
		if (hours<10) {
			hours = "0"+hours;
		}
		if (min<10) {
			min = "0"+min;
		}
	}
	var segs = int(((secs%60)*100)/100);
	if (segs<10) {
		segs = "0"+segs;
	}
	return (hours) ? hours+":"+min+":"+segs : min+":"+segs;
}
//-------------------------- Playback controls and Scrub-------------------//
mcControls.mcPlay.onRelease = function():Void  {
	if (paused) {
		ns.pause();
		paused = !paused;
	}
};
mcControls.mcNext.onRelease = function():Void  {
	currentVideo++;
	if (currentVideo == totalVideos) {
		currentVideo = 0;
	}
	cList.selectedIndex = currentVideo;
	populateFields(currentVideo);
	playVideo(aVideos[currentVideo].source);
};
mcControls.mcPrevious.onRelease = function():Void  {
	currentVideo--;
	if (currentVideo<0) {
		currentVideo = totalVideos-1;
	}
	cList.selectedIndex = currentVideo;
	populateFields(currentVideo);
	playVideo(aVideos[currentVideo].source);
};
mcControls.mcForward.onPress = function():Void  {
	this.onEnterFrame = function():Void  {
		ns.seek(ns.time+scrubSpeed);
	};
};
mcControls.mcForward.onRelease = function():Void  {
	delete this.onEnterFrame;
};
mcControls.mcRewind.onPress = function():Void  {
	this.onEnterFrame = function():Void  {
		ns.seek(ns.time-scrubSpeed);
	};
};
mcControls.mcRewind.onRelease = function():Void  {
	delete this.onEnterFrame;
};
mcControls.mcPause.onRelease = function():Void  {
	ns.pause();
	paused = !paused;
};
mcProgressBar.mcPlayhead.onPress = function():Void  {
	clearInterval(nPlayback);
	this.startDrag(true, 0, this._y, mcProgressBar.mcDownloadBar._xscale*1.5, this._y);
	this.onEnterFrame = function():Void  {
		ns.seek(this._x*totalLength/150);
	};
};
mcProgressBar.mcPlayhead.onRelease = function():Void  {
	this.stopDrag();
	delete this.onEnterFrame;
	nPlayback = setInterval(playback, 1000/24);
};
mcProgressBar.mcPlayhead.onReleaseOutside = mcProgressBar.mcPlayhead.onRelease;
//-------------------------- MUTE BUTTON ----------------------------------------------------//
var flvSound_mc:MovieClip = _root.createEmptyMovieClip("flvSound_mc", _root.getNextHighestDepth());
flvSound_mc.attachAudio(ns);
var soundHolder_sound:Sound = new Sound(flvSound_mc);
soundHolder_sound.setVolume(100);
mcMute.onRelease = function():Void  {
	if (soundHolder_sound.getVolume() == 100) {
		soundHolder_sound.setVolume(0);
		mcMute.gotoAndStop(2);
	} else {
		soundHolder_sound.setVolume(100);
		mcMute.gotoAndStop(1);
	}
};
//-----------------------------------TOOL TIPs For controls--------------------------------------------//
mcTip.tText.autoSize = "left";
mcControls.mcPlay.onRollOver = toolTip;
mcControls.mcForward.onRollOver = toolTip;
mcControls.mcRewind.onRollOver = toolTip;
mcControls.mcNext.onRollOver = toolTip;
mcControls.mcPrevious.onRollOver = toolTip;
mcControls.mcPause.onRollOver = toolTip;
mcControls.mcPlay.onRollOut = resetTip;
mcControls.mcRewind.onRollOut = resetTip;
mcControls.mcForward.onRollOut = resetTip;
mcControls.mcNext.onRollOut = resetTip;
mcControls.mcPrevious.onRollOut = resetTip;
mcControls.mcPause.onRollOut = resetTip;
mcControls.mcPlay.onRollOut = resetTip;
function toolTip():Void {
	switch (this) {
	case _level0.mcControls.mcNext :
		mcTip.tTip.text = "next";
		break;
	case _level0.mcControls.mcPrevious :
		mcTip.tTip.text = "previous";
		break;
	case _level0.mcControls.mcForward :
		mcTip.tTip.text = "forward";
		break;
	case _level0.mcControls.mcRewind :
		mcTip.tTip.text = "rewind";
		break;
	case _level0.mcControls.mcPlay :
		mcTip.tTip.text = "play";
		break;
	case _level0.mcControls.mcPause :
		mcTip.tTip.text = "pause";
		break;
	}
	this.onEnterFrame = function():Void  {
		mcTip._x = _xmouse;
	};
}
function resetTip():Void {
	delete this.onEnterFrame;
	mcTip.tTip.text = "";
}
//-------------------------PLAYLIST TAB FUNCTIONALITY ----//
mcTab.mcHit.onRollOver = function():Void  {
	mcTab.play();
};
//-----------------------------clear intervals ---------------------//
function clearIntervals():Void {
	clearInterval(nDownload);
	clearInterval(nPlayback);
}
Gracias por todo.
__________________
juanmax - GUERRERO Lab
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 20:54.