Creating a Video Player in AS3 using NetStream

I always try to opt from using the flv player component.. although it saves us half the work when it comes to accessing the properties and methods, sometimes it is still very heavy (in size) compared to this approach that really doesn’t add anything worth mentioning

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

public class videoPlayer
{
	public function videoPlayer():void
	{

		var customClient = new Object();
		customClient.onMetaData = metaDataHandler;

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

		var ns = new NetStream(nc);
		ns.client = customClient;
		var vid = new Video(320, 240);
		vid.name = "vid";

 		this.addChild(vid);
		vid.attachNetStream(ns);
 		ns.play("videos/videoSample.flv");

		st = new SoundTransform();
 		st.volume=0.5;

		ns.soundTransform=st;
	}

	public function metaDataHandler(infoObject:Object):void {
		for (var prop in infoObject){
			trace(prop+" : "+infoObject[prop]);
		}
	}

}
  1. Marius Bratu says:

    Have a look here, another article on how to create a as3 video player. Thx;)

  2. Gef H says:

    the metaDataHandler function is just what is needed for setting the video parameters before play begins.

  1. There are no trackbacks for this post yet.

Leave a Reply