ActionScript 3 Working with Video Load and play external video file


Example


reference : NetConnection , NetStream , Video

related topics : Working with Sound


Basic example of playing an external video file (FLV, MP4, F4V). Code will also play M4A audio files.

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

var ns:NetStream = new NetStream(nc);

var myVideo:Video = new Video();
addChild(myVideo);

myVideo.attachNetStream(ns);

ns.play("http://www.yourwebsite.com/somefile.mp4");

Notice the code used a nc.connect.null? This is because, in this case, there is no need to create a two-way peer to peer connection (eg: as expected in a video chat app) since we are playing a stored file.

By setting a nc.connect.null it is required to provide a link to a file that is either on a web server or one that is local (same location/folder) to the running SWF.

  • For a web file use : ns.play("http://www.yourwebsite.com/somefile.mp4");
  • For a local file use : ns.play("somefile.mp4");