3

ユーザーがビデオストリームを送信し、他のユーザーがそれを表示できるようにするFlexアプリケーションを導入しようとしています。

送信者ページ(以下)を作成しました。コードは非常にシンプルで、完全に機能します。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.UIComponent;
            import mx.events.FlexEvent;

            // Network properties
            private var connection:NetConnection;
            private var outStream:NetStream;
            private var RTMFP_CODE:String = "A_CODE";

            // Device properties    
            private var camera:Camera;
            private var microphone:Microphone;

            // Video properties
            private var outVideo:Video;

            // Flex components
            private var outVideoWrapper:UIComponent;

            protected function button1_clickHandler(event:MouseEvent):void
            {
                connection = new NetConnection();    
                connection.connect("rtmfp://p2p.rtmfp.net/" + this.RTMFP_CODE);
                connection.addEventListener(NetStatusEvent.NET_STATUS, onConnected);
            }

            private function onConnected(event:NetStatusEvent):void{
                if (event.info.code == "NetConnection.Connect.Success"){
                    setupVideo();
                }
            }

            private function setupVideo():void{
                // Setup outgoing devices
                camera = Camera.getCamera();
                microphone = Microphone.getMicrophone();

                // Setup outgoing stream

                outStream = new NetStream(connection);
                outStream.attachCamera(camera);
                outStream.attachAudio(microphone);
                outStream.publish("flex_rocks");

                // Setup outgoing video and attach outgoing devices
                outVideo = new Video();
                outVideo.attachCamera(camera);

                // Wrap the video object
                outVideoWrapper = new UIComponent;
                outVideoWrapper.addChild(outVideo);
                addElement(outVideoWrapper);
            }
        ]]>
    </fx:Script>
    <s:Button x="885" y="0" label="Send video" click="button1_clickHandler(event)"/>
</s:Application>

次に、受信者のページコード(以下)が表示されます。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.core.UIComponent;
            import mx.events.FlexEvent;

            // Network properties
            private var connection:NetConnection;
            private var inStream:NetStream;
            private var RTMFP_CODE:String = "A_CODE";

            // Device properties
            private var camera:Camera;
            private var microphone:Microphone;

            // Video properties
            private var inVideo:Video;

            // Flex components

            // private var inVideoWrapper:UIComponent;

            protected function button1_clickHandler(event:MouseEvent):void
            {
                connection = new NetConnection();
                connection.connect("rtmfp://p2p.rtmfp.net/" + this.RTMFP_CODE);
                connection.addEventListener(NetStatusEvent.NET_STATUS, onConnected);
            }

            private function onConnected(event:NetStatusEvent):void{
                Alert.show(event.info.code);
                if (event.info.code == "NetConnection.Connect.Success"){
                    setupVideo();
                }
            }

            private function setupVideo():void{
                // Setup outgoing devices

                camera = Camera.getCamera();
                microphone = Microphone.getMicrophone();

                // Setup incoming stream
                inStream = new NetStream(connection);
                inStream.play("flex_rocks");

                // Setup incoming video and attach incoming stream
                inVideo = new Video();
                inVideo.attachNetStream(inStream);

                // Wrap the video object

                // inVideoWrapper = new UIComponent();   
                inVideoWrapper.addChild(inVideo);
                addElement(inVideoWrapper);
            }
        ]]>

    </fx:Script>
    <s:Button x="885" y="0" label="Receive a stream" click="button1_clickHandler(event)"/>
    <mx:UIComponent id="inVideoWrapper" x="0" y="0" width="500" height="500">
    </mx:UIComponent>    
</s:Application>

レシーバーページに着信ストリームを表示できない理由がわかりません。返された接続コードを表示する簡単なアラートを配置しました。「成功」と表示されます。

私は何か間違ったことをしていますか?

よろしく。

(追記:WindowsSeven64ビットでFlexBuilder4を使用しています)。

4

1 に答える 1

2

p2pにCirrusを使用している場合は、両方をCirrusに接続するだけではまったく役に立ちません。event.nearID発生する必要があるのは、Cirrusに接続し、onConnectedハンドラーで使用しているサービスから必要なIDを取得することです。また、次のように2つのクライアント間で直接接続できるようにストリームを指定する必要があります。

outStream = new NetStream(connection, NetStream.DIRECT_CONNECTIONS);

そして、これは物事が面白くなるところです、あなたは今そのIDを受信者に転送する必要があります。Cirrusはあなたのためにそれをしません。送信または手動で入力するサービスが必要です。手動で入力したとすると、受信側はこれを使用して接続する必要があります。

inStream = new NetStream(connection, cirrusID);

そして、それは順番に両方のクライアントを互いに直接接続します。

于 2011-03-29T16:53:53.950 に答える