views:

1829

answers:

2

I'm doing a project where we play multiple videos back to back, and if we load them the normal way by providing a stream url, there is a load delay each time we start the next video.

I've looked through Adobe's docs for both Flash and Flex, and I can't find a way to pre-load the videos. Embedding them is not workable in this application. Ideally we would pre-load them, display a progress bar or other short video in the meanwhile, and only start the video playback when all the videos have loaded.

I'm not used to asking questions of others for programming, I RTFM, but I find the Adobe docs to be lacking, and googling flash/flex problems is tough. There's a lot to sift through, and I can't find the relevant technique/solution.

As to Flex/Flash I'm interested in the solution for either, or both. Perhaps it is the same, as it is actionscript?

+3  A: 

You could try looking at the bulk-loader project and see if it might be useful for this.

An excerpt from the front page:

"BulkLoader is a minimal library written in Actionscript 3 (AS3) that aims to make loading and managing complex loading requirements easier and faster. BulkLoader takes a more dynamic, less architecture heavy aproach [sic]. Few imports and making heavy use of AS3's dynamic capabilities, BulkLoader has a one-liner feel that doesn't get in your way."

hasseg
+1  A: 

This should be very straightforward. For straight flash, use either fl.video.VideoPlayer or fl.video.FLVPlayback. Create multiple players, one per video, calling load() on each with the url to your source video. Then listen for VideoProgressEvent.PROGRESS events to find out when the video is loaded. Finally, you can attach the videos in succession to a visual component and call play() to play them.

Example code(not tested):

var video1:VideoPlayer = new VideoPlayer();
video1.load("http://example.com/video1.flv");
video.addEventListener(VideoProgressEvent.PROGRESS,
                       function(e:VideoProgressEvent):void
                       {
                         if (e.bytesLoaded == e.bytesTotal)
                         {
                           trace("video1 loaded.");
                           parent.addChild(video1);
                           video1.play();
                         }
                       }
var video2:VideoPlayer = new VideoPlayer();
video2.load("http://example.com/video1.flv");
video.addEventListener(VideoProgressEvent.PROGRESS,
                       function(e:VideoProgressEvent):void
                       {
                         if (e.bytesLoaded == e.bytesTotal)
                         {
                           trace("video2 loaded.");
                         }
                       }
Scotty Allen