移植 Adob​​e Air 应用程序以在 Android 设备上运行

发布于 2024-12-28 03:21:56 字数 3704 浏览 0 评论 0原文

我在博客上找到了一个示例,介绍如何使用 Adob​​e 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>

I found a example on a blog, how its possible to use the Adobe Cirrus to develope real-time collaboration applications. I this case its a videochat client, but the thing is that the code is written to run at desktops, not mobile devices. So my question, is there any chance to run this sample code on an android device?

The sample code

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文