项目姑且取名为 pzaixianluzhi 吧,pzaixianluzhi.mxml 内容如下:
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:UIComponent id="ui"> </mx:UIComponent> <mx:Script> <![CDATA[ import mx.controls.Alert; private var rtmpURL:String="rtmp://localhost/ExampleWebPro"; private var conn:NetConnection=new NetConnection(); private var isConnectSuccess:Boolean=false; private var netStream:NetStream; private var video:Video=new Video(); private function clickConnect(e:MouseEvent):void{ if(!isConnectSuccess){ conn.addEventListener(NetStatusEvent.NET_STATUS,netStatus); conn.connect(rtmpURL); } } private function clickVideo(e:MouseEvent):void{ video.attachCamera(Camera.getCamera()); ui.addChild(video); } private function netStatus(e:NetStatusEvent):void{ trace(e.info.code); if(e.info.code=="NetConnection.Connect.Success"){ isConnectSuccess=true; netStream=new NetStream(conn); netStream.client=new StreamClient(); netStream.attachAudio(Microphone.getMicrophone()); netStream.attachCamera(Camera.getCamera()); netStream.publish("nameffff","record"); } } ]]> </mx:Script> <mx:Button x="378" y="369" label="录制" click="this.clickConnect(event)" fontSize="16"/> <mx:Button x="310" y="369" label="视频" fontSize="16" click="this.clickVideo(event)"/> </mx:Application>
pzaixianluzhi.mxml 调用到的 StreamClient.as 源码如下:
package { public class StreamClient { public function StreamClient() { } public function onMetaData(info:Object):void{ for(var n:* in info){ trace(n+":"+info[n]); } } public function onPlayStatus(info:Object):void{ for(var n:* in info){ trace(n+":"+info[n]); } } } }
将 %Red5%webapps/messageRecorder/WEB-INF 下的 red5-web.properties 和 red5-web.xml 文件复制到 ExampleWebPro 项目的 WEB-INF 下,然后在 web.xml 中添加如下内容:
<context-param> <param-name>webAppRootKey</param-name> <param-value>/ExampleWebPro</param-value> </context-param>