控制FLVPlayback的NetConnection

很不幸,我把原文的地址给忘掉了。这是国外一个论坛上的帖子,希望对大家有帮助。

Accessing the NetConnection Object in FLVPlayback

Posted At : August 14, 2009 9:13 AM | Posted By : Stefan Richter | Related Categories: Components , FMS , Videos & Players

 

 

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.

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值