Archive | November 2010

BitmapData.draw() RTMP streaming

In many circumstances you may want to use BitmapData.draw() method to draw a Video Object into a Bitmap. Perhaps you want to take a ‘snapshot’ of a video stream,or to create some effects within the stream. If the stream is carried by http protocal,you just have to place a crossdomain.xml file on the domain where your flv files are.

However,there is no such policy file could be applied with rtmp protocal. So you should follow these two ways below to configure FMS setting. Either of them is OK.

1.Add this in FMS server side main.asc file:

client.videoSampleAccess="/";

2.If you are using FMSS(not the full version of FMS),you have no way to define server side Script. Then you can open the global config xml file,locate the VideoSampleAccess Tag,edit the node value. Note it must be a stroke as the node value:

<VideoSampleAccess enabled="true">/</VideoSampleAccess>

Get current url to Flash swf without using External Interface call

Note it’s “without using External Interface call”,and I found out an interesting way to get current page url to Flash by FMS.

In swf:

package 
{
	import flash.display.Sprite;
	import flash.net.NetConnection;
	import flash.events.NetStatusEvent;
	import flash.net.Responder;

	public class Link extends Sprite
	{
		var nc:NetConnection;

		public function Link()
		{
			nc = new NetConnection();
			nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
			nc.connect("rtmp://server_url/app");
		}
		public function __onRes(arg:String):void
		{
			trace("current html page url:" + arg);
			nc.close();
		}


		private function netStatusHandler(event:NetStatusEvent):void
		{
			switch (event.info.code)
			{
				case "NetConnection.Connect.Success" :
					var ro:Responder = new Responder(__onRes);
					nc.call("getPageUrl", ro);
					break;
			}
		}
	}
}

FMS server side ASC file:

application.onConnect = function(client)
{
    this.acceptConnection(client); 
    client.getPageUrl = function(msg)
    {
        return this.pageUrl;
    };
};

Haha,hope you like it!