Friday, March 13, 2009

Playing multiple videos Dynamically

import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;

Create a connection object

var connection_nc:NetConnection = new NetConnection();
connection_nc.connect(null);

Create a NetStream object and pass the NetConnection object

var stream_ns:NetStream = new NetStream(connection_nc);
stream_ns.client = new Object();

One connection object can be used for more than one video stream.

myVideo.attachNetStream(stream_ns);
stream_ns.play("video.flv");

myVideo is the name of my video object placed on the stage & video.flv is the video file which needs to be played. Now if you want to play another video you have to create a new NetStream object for each video otherwise it will not work. I spent 4 hours just to figure this out & kept trying different techniques to make my 4 different videos work with the same NetStream object. But unfortunately it is not possible.

So guys the trick is to create different NetStream object for each video & have fun.

Happy Streaming!!!

1 comment:

Anonymous said...

Brilliantly clear, thanks Atul - a real help.