Flex 支持的 P2P 音视频流

晨曦之光 发布于 2012/04/24 14:44
阅读 770
收藏 0

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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

applicationComplete="{init();}" >

<mx:Script>

<![CDATA[

import mx.core.UIComponent;

private var nc:NetConnection;

private var rtmfpServer:String = 'rtmfp://localhost:1935/';

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>

</mx:Application>



原文链接:http://blog.csdn.net/poechant/article/details/7466752
加载中
0
王昕峰
请问个问题  server   rtmfp://localhost:1935/ 这个是什么意思??
返回顶部
顶部