How to make multiple videoclips play simultaneous from Actionscript 3.0
I am trying to do a little multimedia player where I have at least 9 small videoclips that I would like to place and play - all controlled by AS 3.0.
It might even be more than 9 clips, but they will show randomly in 9 p开发者_如何学编程laces. A movie can switch viewport too.
I will preload them all into buffers and I would like to play them randomly at the same time.
This means that there could be 9 equally sized areas showing small movieclips including sound and random times.
Like this:
[1][2][3]
[4][5][6]
[7][8][9]
So its 1 Flash canvas/player showing them all at the same time.
Is this possible or will it crash Flash to play 9 movies including their sound? The movies might be of different length and will have to be reset and played many times, but I cant prerender the result as its randomly generated from user input.
Any sharp AS 3.0 guru in here who can point me in the right direction for this idea?
EDIT
like in... an example code of where to start? I've been thinking that I could put all the parts into one "sprite movie" and the play from frame XYZ for each "window" - but not sure how or if it will work... nor whats best approach.
I think it's more than possible. You create 9 video objects and you need 9 NetStreams for them. You set a timer to start each video respectively.
So the easiest is to have 9 flv names in an array, and 9 times in an array. Then you create a loop, where you create the 9 video objects, arrange them in a matrix, then use a timeout to start each at the specific time.
The easiest and shortest code I can think of is as follows:
//we use the same flv now
var flvs:Array = ["filename.flv", "filename.flv", "filename.flv", "filename.flv", "filename.flv", "filename.flv", "filename.flv", "filename.flv", "filename.flv"];
//setting the times in milliseconds
var times:Array = [0, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000];
//creating a NetConnection
var nc:NetConnection = new NetConnection();
//connect null, the flv is in the same folder and a simple file loading
nc.connect(null);
//the loop
for(var i:int = 0; i < times.length; i++)
{
var ns:NetStream = new NetStream(nc);
var video:Video = new Video(100, 100);
addChild(video);
//i%3 and int(i/3) arranges them in a 3x3 matrix
video.x = (i%3) * video.width;
video.y = int(i/3) * video.height;
video.attachNetStream(ns);
//the tricky timeout to call the funcion playFlv, in times[i] time, for the specific nc NetStream to play the given flvs[i] flv
flash.utils.setTimeout(playFlv, times[i], ns, flvs[i]);
}
function playFlv(ns:NetStream, flv:String):void
{
ns.play(flv);
}
Yes this is definitely possible. You will want to optimize you videos as much as possible of course. There is precedent for this in the Pine Point website, (you'll have to navigate to the "shelf life" section, and hit "next" a few times to see it) It is playing 12 videos at once, all different lengths. In terms of building it, its no different than playing one video, just repeat the steps X number of times.
I hope that helps,
精彩评论