FlashComGuru Home InfluxisCDNImediaseeUvault
                                                                                       Forum Index | Active Topics | Register
                                                                                                          List Overview | List Archives
                                                                                                                           About this site | Advertise
 

home

Adobe AIR (11)
Applications (40)
Books & Training (11)
Collaboration (18)
Components (10)
Events (80)
Flash Player (35)
Flex (39)
FMS (110)
General (123)
Hosting (6)
Jobs (17)
Off topic (36)
OSMF (3)
Press Releases (23)
Site Check (11)
Tools (53)
Videos & Players (74)

Follow me on Twitter

 
There are situations where it is necessary to call a server side method on FMS. Some CDNs, for example Limelight, used to or maybe still do require you to call the FCSubscribe method in order to request a live stream. This send a signals to the Edge server to pull the live stream from the Origin server if it is not already being delivered to that Edge. While this delivery method and stream setup routine is being phased out across most CDNs I thought it may be useful to post a (slightly hackish) workaround to make this setup work with the FLVPlayback component.
The problem with the FLVPlayback component is that there is no obvious, simple way to obtain a reference to the NetConnection Object it uses under the hood. Sure, the ncMgr.getNetConnection let's you grab it but only once the connection is established, and while you can implement a custom NCManager class, this is not trivial and after all a NetConnection is being maintained already by the component, so why reinvent the wheel?

The following code is clearly not something I am proud of, but it worked at the time when I needed it. It was used to get a live stream working with the FLVPlayback component streaming from Limelight about a year or two ago.

// listen to player events and kill manual connection once we're streaming
   player.addEventListener("playing", playListener);
   player.addEventListener("stateChange", stateListener);
   player.addEventListener("ready", readyListener);
      
/* this is the hack: check once every frame if the NC has been defined inside the FLVPlayback component */   
   this.onEnterFrame = function()
   {
      if (player.ncMgr.getNetConnection() != undefined)
      {
         this.onEnterFrame = null;
         delete this.onEnterFrame;
         trace("got NC");
         //subscribe(streamName);       }
   }
         
   var nc:NetConnection;
   var serverName:String = "server.llnwd.net";
   var appName:String = "account_name/_definst_";
   var streamName:String = "live";
   
   var source_Str = "rtmp://" + serverName + "/" + appName + "/" + streamName;
   
   // start up by setting the contentPath (now called source in newer versions of the component)    
player.contentPath = source_Str;   
   
   function subscribe(name:String)
   {
      nc = player.ncMgr.getNetConnection();
         
      nc.onFCSubscribe = function(info:Object)
      {
         trace("onFCSubscribe: " + info.code);
         clearInterval(int_id);

         if (info.code == "NetStream.Play.StreamNotFound")
         {
            // handle error, retry after a few secs or similar          }
         else if (info.code == "NetStream.Play.Start")
         {
            // we're successfully subscribed          }
         else
         {
            // handle error          }
      };
         
      
// not used right now       
nc.onFCUnsubscribe = function(info:Object)
      {
      }
         
      trace("subscribing to " + name);
      nc.call("FCSubscribe",null,name);
   }
   
   // can be used to unsubscribe from stream    
function unsubscribe(name:String)
   {
      nc.call("FCUnsubscribe",null,name);
   }

Hopefully this is helpful to someone.

Comments
[Add Comment]
Thanks for posting this. I'm going to try it out with one of my FLVPLayers. I'll post back with success or failure.

Have you ever seen someone live stream using the Video object? I see tons of VOD with it but can't seem to find an example of live streaming. It must be possible.
# Posted By Robert | 8/14/09 8:26 PM
video object or video display component? In Flex you mean?

I've seen video object used in both Flash and Flex a lot. I personally don't use the video display comp in Flex at all.
# Posted By Stefan Richter | 8/14/09 10:04 PM
i have used the video:Object for live video its very useful i can send you some snippets if you want me to
# Posted By Ramon Roche | 8/15/09 2:18 AM
Yes, please do. That's exactly what I need - the video:Object (not Flex VideoDisplay). It's the only class that seems to expose the underlying NetConnection object, which is what I need to customize. As I mention, I see it used a lot with VOD. I've not been able to find snippets that work with live streaming. I've tried to morph some of the working VOD examples into live streaming versions but to no avail. I must be missing something.

Any functioning snippets you have would be greatly appreciated.
# Posted By Robert | 8/15/09 2:35 AM
i try to test this example but i can't to acccess the function nc.onFCUnsubscribe. how i can to do it?
# Posted By walter Vargas | 8/24/09 2:21 PM
The FMS docs have this example for live video that uses a Video object:

http://help.adobe.com/en_US/FlashMediaServer/3.5_D...
# Posted By AdobeDocs | 8/25/09 9:35 PM