?
Solved

How to preload multiple FLVs for smooth playback?

Posted on 2008-11-17
3
Medium Priority
?
1,244 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:Mindspace
  • 2
3 Comments
 
LVL 8

Expert Comment

by:wal_toor
ID: 22984431
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
 

Author Comment

by:Mindspace
ID: 22984573
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
 
LVL 8

Accepted Solution

by:
wal_toor earned 1500 total points
ID: 22989504
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question