How to preload multiple FLVs for smooth playback?

I am attaching a snippet of code that I am using to display multiple flvs. However, what I can't figure out is how to preload the 2nd while the first is playing.

Any support would be greatly appreciated!

var vidConnection:NetConnection = new NetConnection;
var vidStream:NetStream = new NetStream(vidConnection);
var video:Video = new Video(350,288);
var video2:Video = new Video(380,530);
var infoClient:Object = new Object();
var container:Sprite = new Sprite();
infoClient.onMetaData = onMetaData;
infoClient.onCuePoint = onCuePoint;
vidStream.client = infoClient;
vidStream.bufferTime = 20;
vidStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);"myflv.flv");
function onMetaData(info:Object):void
function onCuePoint(info:Object):void
function netStatusHandler(event:NetStatusEvent):void
        switch (
            case "NetStream.Play.Stop":
		video2.width = 380;
		video2.height = 530;
    catch (error:TypeError) 
        // Ignore any errors.

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


I have found this link about preloading flv files. Maybe this can help you.

MindspaceAuthor Commented:
Thanks for your comment. This actually won't be in a web page, so I'll need to find a solution that is based on AS3.
Maybe this helps. I have created a sequential preloader for flv movies. Put the flvurl, netstream object and video object in an array and let as loop through this array. It preloads the movie, after complete loading it will play.

For this example create two video objects on the stage and call them "my_video0" and "my_video1", the script does the rest.

I hope that this can help you any further.


p.s. I have done this in AS2, hope you can port this to AS3
var connection_nc:NetConnection = new NetConnection();
var loaded_interval:Number;
// create as many netstreams as there are elements in array
var stream_ns0:NetStream = new NetStream(connection_nc);
var stream_ns1:NetStream = new NetStream(connection_nc);
// create flv array
var flvArray:Array = new Array(["", stream_ns0, my_video0],
							   ["", stream_ns1, my_video1]);
function checkBytesLoaded(flvLocation:Number){
	var myVideo:Video = flvArray[flvLocation][2];
	var myNetstream:NetStream = flvArray[flvLocation][1];
	//var myFlvLocation:String = flvArray[flvLocation][0];
	var pctLoaded:Number = Math.round(myNetstream.bytesLoaded/myNetstream.bytesTotal*100);
	trace("flv clip["+flvLocation+"] loaded = "+pctLoaded+" %");
	if (pctLoaded>=100){
		// kill interval
		// get next flv to load if there are any
		if(flvLocation < flvArray.length){
			loadNextFLV(flvLocation, myVideo);
// load next flv function
function loadNextFLV(flvLocation:Number):Void{
	var myVideo:Video = flvArray[flvLocation][2];
	var myNetstream:NetStream = flvArray[flvLocation][1];
	var myFlvLocation:String = flvArray[flvLocation][0];
	// check loading progress
	loaded_interval = setInterval(this, "checkBytesLoaded", 100, flvLocation);
// preload firs movie of array

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.