2012-03-22 75 views
0

我有問題讓我的flex代碼工作,下面是我的代碼,我嘗試netstream網絡攝像頭並接收它並使用2個功能。任何flex大師都可以幫我修復這些功能?newbie:flex netstream如何讓我的代碼流和正確接收netstreams?

  function onNetConnectionPublish():void { 
       StatusMessage("onNetConnectionPublish called"); 
       ncNetStream = new NetStream(nc, NetStream.DIRECT_CONNECTIONS); 
       ncNetStream.addEventListener(NetStatusEvent.NET_STATUS, sendNetStreamHandler); 
       ncNetStream.publish("media"); 
       ncNetStream.attachAudio(Microphone.getMicrophone()); 
       ncNetStream.attachCamera(Camera.getCamera()); 
      } 

和:

  function connectToRemote(remoteId:String) { 
       StatusMessage("connectToRemote(" + remoteId + ")"); 

       ncNetStream = new NetStream(nc, remoteId); 
       ncNetStream.addEventListener(NetStatusEvent.NET_STATUS, receiveNetStreamHandler); 
       ncNetStream.play("media"); 
      } 

顯示視頻:

回答

1

發佈者應用:

private function Publisher():void{ 

     var camera1:Camera = Camera.getCamera(); 
     var video:Video = new Video(285, 254); 
     if (camera1) 
     { 
      video.attachCamera(camera1); 
      VideoDisplay1.addChild(video); 
      camera1.addEventListener(ActivityEvent.ACTIVITY, camera_activity); 
      camera1.addEventListener(StatusEvent.STATUS, camera_status); 
     } 

     var nc:NetConnection = new NetConnection(); 
     nc.connect("rtmp://your/stream/url"); 
     nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler); 

     function netStatusHandler(event:NetStatusEvent):void { 
      switch (event.info.code) { 
       case "NetConnection.Connect.Success": 
        var ns:NetStream = new NetStream(nc,NetStream.CONNECT_TO_FMS); 
        ns.attachCamera(camera1); 
        ns.publish("videofeed", "live"); 
        break; 
       case "NetStream.Play.StreamNotFound": 
        trace("Unable to locate video: "); 
        break; 
        } 
      } 
    } 

的Reciever應用:

 import mx.utils.ObjectUtil; 

     private var nc:NetConnection; 
     private var ns:NetStream; 
     private var video:Video; 
     private var meta:Object; 

     private function init():void { 
      var nsClient:Object = {}; 
      nsClient.onMetaData = ns_onMetaData; 
      nsClient.onCuePoint = ns_onCuePoint; 

      nc = new NetConnection(); 
      nc.connect(null); 

      ns = new NetStream(nc); 
      ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv"); 
      ns.client = nsClient; 

      video = new Video(); 
      video.attachNetStream(ns); 
      uic.addChild(video); 
     } 

     private function ns_onMetaData(item:Object):void { 
      trace("meta"); 
      meta = item; 
      // Resize Video object to same size as meta data. 
      video.width = item.width; 
      video.height = item.height; 
      // Resize UIComponent to same size as Video object. 
      uic.width = video.width; 
      uic.height = video.height; 
      panel.title = "framerate: " + item.framerate; 
      panel.visible = true; 
      trace(ObjectUtil.toString(item)); 
     } 

     private function ns_onCuePoint(item:Object):void { 
      trace("cue"); 
     } 

Reciever MXML代碼:

<mx:Panel id="panel" visible="false"> 
    <mx:UIComponent id="uic" /> 
    <mx:ControlBar> 
     <mx:Button label="Play/Pause" click="ns.togglePause();" /> 
     <mx:Button label="Rewind" click="ns.seek(0); ns.pause();" /> 
    </mx:ControlBar> 
</mx:Panel> 
+0

THX讓我在正確的方向 – Ilse 2012-03-27 07:49:18

+0

@sub_stantial:引用源。接收器是[由Peter deHaan撰寫](http://blog.flexexamples.com/2008/03/01/displaying-a-video-in-flex-using-the-netconnection-netstream-and-video-classes/ )。 – approxiblue 2012-06-07 14:19:10

+0

對不起,我的錯。 – Subodh 2012-06-18 08:58:12