0 Replies Latest reply on Oct 11, 2010 9:05 AM by gjhdigital

    Multicast video player with FMS 4.0

    gjhdigital Level 1

      I am trying to create a video player in Flash Builder using the new Flash Media Server 4.0 capabilities but I am not able to. The only thread I've seen out there is regarding the P2P player which is not what I want as seen here:

      http://www.swfgeek.net/2010/08/10/multicast-streaming-in-flash-player-10-1-revisited/

       

      I want to create a custom player that can retrieve a multicast broadcast.

       

      Here is my code:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" width="650" height="250">
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <fx:Script>
          <![CDATA[
          import mx.core.UIComponent;
         
          import spark.components.Group;
       
          private const SERVER:String = "rtmfp://172.22.2.150/multicast";
          private const DEVKEY:String = ""; //removed for now
             
         
          [Bindable]
          private var connected:Boolean = false;
         
          private var video:Video;
         
          private var netConnection:NetConnection;
          private var stream:NetStream;
         
          public function init():void{
          writeText("Broadcaster:");
          video = new Video(320,240);
          video.x = 10;
          video.y = 10;
         
          var uic:UIComponent = new UIComponent();
          uic.addChild(video);
         
          addElement(uic);
         
          connect();
          }
         
          private function connect():void{
          netConnection = new NetConnection();
          netConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
          netConnection.connect(SERVER+DEVKEY);
          }
         
         
          private function onNetConnectionNetStatus(event:NetStatusEvent):void
          {
          switch(event.info.code){
          case "NetStream.Connect.Success":
          event.info.stream.dispatchEvent(event);
          break;
          }
          }
         
          private function netStatus(event:NetStatusEvent):void{
          writeText(event.info.code);
         
          switch(event.info.code){
          case "NetConnection.Connect.Success":
         
          setupStream();
          break;
          case "NetStream.Connect.Success":

       

          // not using a camera, using another live video source
          //var cam:Camera = Camera.getCamera();   
          //stream.attachCamera(cam);
          //stream.publish("multicast");
          //video.attachCamera(cam);

       

          stream.attach(netConnection);
          stream.publish("myStream");
          video.attachNetStream(stream);
             
          break;
          }
         
          }
         
          private function setupStream():void{
         
          //var groupspec:GroupSpecifier = new GroupSpecifier("myGroup/multicastOne");
              var groupspec:GroupSpecifier = new GroupSpecifier("fms.multicast.example");
          groupspec.serverChannelEnabled = true;
          groupspec.multicastEnabled = true;
          groupspec.groupspecWithoutAuthorizations()
          stream = new NetStream(netConnection,groupspec.groupspecWithAuthorizations());
          stream.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
         
         
         
          }
         
          private function writeText(txt:String):void{
          txtHistory.text += txt+"\n";
          }
         
          ]]>
          </fx:Script>
          <s:TextArea top="10" bottom="10" id="txtHistory" width="250" right="10"/>
      </s:Group>