移植Adobe Air应用程序以在Android设备上运行

时间:2012-01-21 14:36:40

标签: android flex flexbuilder adobe-cirrus

我在博客上找到了一个例子,它如何使用Adobe Cirrus来开发实时协作应用程序。在这种情况下,它是一个视频聊天客户端,但问题是代码是在桌面而不是移动设备上运行的。所以我的问题是,有没有机会在Android设备上运行此示例代码?

示例代码

<?xml version="1.0" encoding="utf-8"?>

<mx:Script>
    <![CDATA[
        import mx.core.UIComponent;
        private var nc:NetConnection;
        private var rtmfpServer:String = "rtmfp://p2p.rtmfp.net/DEVELOPER-KEY-HERE/";
        private var sendNS:NetStream;
        private var neerPeerID:String;

        private var cam:Camera;
        private var mic:Microphone;

        private function init():void {
            initCamera();
            initNetConnection();
        }

        private function initCamera():void {
            if (Camera.names.length > 0) { 
                cam = Camera.getCamera();
                my_video_display.attachCamera(cam);
            }

            if (Microphone.names.length > 0) {
                mic = Microphone.getMicrophone();
            }
        }

        private function initNetConnection():void {
            nc = new NetConnection();
            nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusEvent);
            nc.connect(rtmfpServer);
        }

        private function netStatusEvent(event:NetStatusEvent):void {
            trace('NetConnection status event (1): ' + event.info.code);
            if (event.info.code == 'NetConnection.Connect.Success') {
                neerPeerID = nc.nearID;
                farPeerId_text.text = neerPeerID;
                initSendNetStream();
                add_contact_container.visible = true;
            }
        }

        private function initSendNetStream():void {
            sendNS = new NetStream(nc, NetStream.DIRECT_CONNECTIONS);
            sendNS.addEventListener(NetStatusEvent.NET_STATUS, netStatusEvent);

            var clientObject:Object = new Object();
            clientObject.onPeerConnect = function(ns:NetStream):Boolean {return true;}

            sendNS.client = clientObject;
            sendNS.attachCamera(cam);
            sendNS.attachAudio(mic);
            sendNS.publish('video');
        }

        private function addContact():void {
            var nc2:NetConnection = new NetConnection();
            nc2.addEventListener(NetStatusEvent.NET_STATUS, function (event:NetStatusEvent):void {
                trace('NetConnection status event (2): ' + event.info.code);
                var receiveNS:NetStream = new NetStream(nc2, contact_peer_id_text.text);
                receiveNS.addEventListener(NetStatusEvent.NET_STATUS, netStatusEvent);
                receiveNS.play('video');

                var video:Video = new Video();
                video.attachNetStream(receiveNS);

                var uic:UIComponent = new UIComponent();
                uic.width = 320;
                uic.height = 240;
                uic.addChild(video);
                video_stack.addChild(uic);

                contact_peer_id_text.text = '';
            });
            nc2.connect(rtmfpServer);
        }
    ]]>
</mx:Script>

<mx:HBox id="video_stack" top="10" left="10">
    <mx:VBox>
        <mx:VideoDisplay id="my_video_display" width="320" height="240"/>
        <mx:HBox>
            <mx:TextInput width="320" id="farPeerId_text" text="Your Peer ID is loading..."/>
        </mx:HBox>
        <mx:HBox id="add_contact_container" visible="false">
            <mx:TextInput id="contact_peer_id_text" width="200"/>
            <mx:Button label="Add contact" click="{addContact();}"/>    
        </mx:HBox>
    </mx:VBox>
</mx:HBox>

0 个答案:

没有答案