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;
vidConnection.connect(null);
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;
video.attachNetStream(vidStream);
 
addChild(container);
container.addChild(video);
vidStream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 
vidStream.play("myflv.flv");
 
function onMetaData(info:Object):void
{
}
function onCuePoint(info:Object):void
{ 
}
function netStatusHandler(event:NetStatusEvent):void
{
	try
    {
        switch (event.info.code)
        {
            case "NetStream.Play.Stop":
		container.removeChild(video);
		video2.width = 380;
		video2.height = 530;
		video2.attachNetStream(vidStream);
		container.addChild(video2);
		vidStream.play("myflv2.flv");
            	
		break;
        }
    } 
    catch (error:TypeError) 
    {
        // Ignore any errors.
    }
}

Open in new window

MindspaceAsked:
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.

wal_toorCommented:
Hello,

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

http://www.askapache.com/htaccess/preload-and-cache-flash-flv-files.html

greetz,
walter
0
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.
0
wal_toorCommented:
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.

greetz,
walter

p.s. I have done this in AS2, hope you can port this to AS3
var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);
 
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(["http://helpexamples.com/flash/video/sheep.flv", stream_ns0, my_video0],
							   ["http://helpexamples.com/flash/video/water.flv", 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){
		myNetstream.pause();
		// kill interval
		clearInterval(loaded_interval);
		// get next flv to load if there are any
		flvLocation++;
		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];
	myVideo.attachVideo(myNetstream);
	myNetstream.play(myFlvLocation);
	myNetstream.pause();
	// check loading progress
	loaded_interval = setInterval(this, "checkBytesLoaded", 100, flvLocation);
}
 
// preload firs movie of array
loadNextFLV(0);

Open in new window

0

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.