Advertisement
sonesh

broadcast

Dec 3rd, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3.                xmlns:s="library://ns.adobe.com/flex/spark"
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init()">
  5.     <fx:Declarations>
  6.         <!-- Place non-visual elements (e.g., services, value objects) here -->
  7.     </fx:Declarations>
  8.     <fx:Script>
  9.         <![CDATA[
  10.             import mx.core.UIComponent;
  11.            
  12.             private const SERVER:String = "rtmfp:";
  13.             private const DEVKEY:String = "";
  14.             private var myMetadata:Object;
  15.            
  16.             [Bindable]private var connected:Boolean = false;
  17.            
  18.             private var video:Video;
  19.            
  20.             private var netConnection:NetConnection;
  21.             private var stream:NetStream;
  22.            
  23.             public function init():void{
  24.                 writeText("Broadcaster:");
  25.                 video = new Video(320,240);
  26.                 video.x = 10;
  27.                 video.y = 10;
  28.                
  29.                 var uic:UIComponent = new UIComponent();
  30.                 uic.addChild(video);
  31.                
  32.                 addElement(uic);
  33.                
  34.                 connect();
  35.             }
  36.            
  37.             private function connect():void{
  38.                 netConnection = new NetConnection();
  39.                 netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
  40.                 netConnection.connect(SERVER+DEVKEY);
  41.             }
  42.            
  43.            
  44.             private function onNetConnectionNetStatus(event:NetStatusEvent):void
  45.             {
  46.                 switch(event.info.code){
  47.                     case "NetStream.Connect.Success":
  48.                         event.info.stream.dispatchEvent(event);
  49.                         break;
  50.                 }
  51.             }
  52.            
  53.             private function netStatus(event:NetStatusEvent):void{
  54.                 writeText(event.info.code);
  55.                
  56.                 switch(event.info.code){
  57.                     case "NetConnection.Connect.Success":
  58.                        
  59.                         setupStream();
  60.                         break;
  61.                     case "NetStream.Connect.Success":
  62.                         var cam:Camera = Camera.getCamera();
  63.                        
  64.                         stream.attachCamera(cam);
  65.                         stream.publish("livestream");
  66.                        
  67.                         video.attachCamera(cam);
  68.                         break;
  69.                 }
  70.                
  71.             }
  72.            
  73.             private function setupStream():void{
  74.                
  75.                 var groupspec:GroupSpecifier = new GroupSpecifier( "fms.multicast.example");
  76.                 groupspec.serverChannelEnabled = true;
  77.                 groupspec.multicastEnabled = true;
  78.                
  79.                 groupspec.setPublishPassword("spencer");
  80.                 groupspec.multicastEnabled = true;
  81.                 groupspec.serverChannelEnabled = true;
  82.                 groupspec.ipMulticastMemberUpdatesEnabled = true;
  83.                 groupspec.addIPMulticastAddress("224.1.1.1:30000");
  84.                
  85.                 stream = new NetStream(netConnection,groupspec.groupspecWithAuthorizations());
  86.                 stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
  87.                
  88.                
  89.                
  90.             }
  91.            
  92.             private function writeText(txt:String):void{
  93.                 txtHistory.text += txt+"\n";
  94.             }
  95.            
  96.             private function sendmeta():void {
  97.                 writeText("Sending metadata");
  98.                 myMetadata = new Object();
  99.                 myMetadata.customProp = "Welcome from sonesh.";
  100.                 //stream.send("@setDataFrame", "onMetaData", myMetadata);
  101.                 stream.send("onStreamData", myMetadata)
  102.                                  writeText("Sent metadata");
  103.             }
  104.         ]]>
  105.     </fx:Script>
  106.     <s:TextArea top="10" bottom="10" id="txtHistory" width="250" right="10"/>
  107.     <s:Button  id="btnMetaData" label="Send Metadata" width="252" right="10"  mouseDown="sendmeta()"/>
  108. </s:Application>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement