新手:flex netstream如何获取我的代码流并正确接收网络流?

时间:2012-03-22 08:22:18

标签: flex video adobe netstream netconnection

我在使用我的flex代码时遇到问题,下面是我的代码我尝试netstream网络摄像头并接收它并使用2个功能。任何flex大师都可以帮我修复这些功能吗?

            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 个答案:

答案 0 :(得分: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;
                    }
             }
    }

接收人申请:

        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");
        }

Receiver 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>