工程行业网站,网站流量用完了,网页制作与网站建设初学者必看教程,哈尔滨网站建设技术托管由于我也是刚开始接触这个东东#xff0c;原理什么的不是很清楚#xff0c;这里我就不说了#xff0c;免得误人子弟#xff0c;嘿嘿#xff01;第一步#xff0c;下载FlashMediaServer3.5#xff0c;网上有很多资源#xff0c;这里就不提供了#xff0c;大家google一下…由于我也是刚开始接触这个东东原理什么的不是很清楚这里我就不说了免得误人子弟嘿嘿第一步下载FlashMediaServer3.5网上有很多资源这里就不提供了大家google一下就可以了这里给一个序列号1373-5209-5319-9982-4515-7002我用地就是这一个。安装完后打开FlashMediaServer3.5服务一个是Start Adobe Flash Media Server 3.5.2另一个是Start Flash Media Administration Server 3.5.2。第二步在FlashMediaServer3.5安装目录下的applications文件夹下新建一个测试文件夹“tests”。这个文件夹后面会用到。第三步下载Flex Builder 3地址我也不提供了网上google一下有很多资源的。安装Flex Builder3第四步编写录音录像程序MyTest。这里的代码是从网上扒的。原文地址http://hi.baidu.com/xulina809/blog/item/6d456db603fb90788bd4b200.html 其中修改了一下我服务器的地址具体代码如下View Code?xml version1.0 encodingutf-8?mx:Application xmlns:mxhttp://www.adobe.com/2006/mxml layoutabsolute creationCompleteplayinit() width366 height350 mx:Script![CDATA[import mx.events.SliderEvent;import mx.events.VideoEvent;import mx.collections.ArrayCollection;import mx.rpc.events.ResultEvent;import mx.core.UIComponent;import flash.events.StatusEvent;import flash.events.SecurityErrorEvent;import flash.media.Camera;import flash.media.Microphone;import flash.net.NetConnection;//由于fms使用的是amf0而flex3中的as3默认使用的是amf3.所以要让flex使用AFM0NetConnection.defaultObjectEncoding flash.net.ObjectEncoding.AMF0;//视频服务端地址private var _videoServerURL:String rtmp://192.168.2.105/tests;private var _camera:Camera; //定义一个摄像头private var _mic:Microphone; //定义一个麦克风private var _localVideo:Video; //定义一个本地视频private var _netConnection:NetConnection;private var _outStream:NetStream; //定义一个输出流private var _inStream:NetStream; //定义一个输入流private var isplaying:Booleanfalse; //定义是否正在播放标记private var isrecing:Boolean false; //定义是否正在录制标记private var ispauseing:Boolean false; //定义是否正在暂停标记private var _duration:Number; //定义视频持续时间private var playPosition:Number; //定义播放进度位置private var soundPosition:Number; //定义声音大小控制条的位置private function playinit():void{t_hs_control.enabledfalse;t_btn_play.enabled false;t_btn_stop.enabled false;t_btn_rec.enabled false;t_btn_save.enabled false;t_lbl_rec.visible false;initCameraAndMic(); //初始化摄像头}//初始化摄像头//判断是否存在摄像头和访问权限private function initCameraAndMic():void{_camera Camera.getCamera();if(_camera ! null){_camera.addEventListener(StatusEvent.STATUS,__onStatusHandler);_camera.setMode(320,420,30);//t_flv_video.attachCamera(_camera);_localVideo new Video();_localVideo.width 320;_localVideo.height 240;_localVideo.attachCamera(_camera);t_flv_video.addChild(_localVideo);}_mic Microphone.getMicrophone();if(_mic ! null){//未添加侦听麦克连接状态//设置本自本地的麦克风的音频传送到本地系统扬声器/*_mic.setUseEchoSuppression(true);_mic.setLoopBack(true);*/_mic.setSilenceLevel(0,-1); //设置麦克风保持活动状态并持续接收集音频数据_mic.gain 80; //设置麦克风声音大小}}//开始录制视频//检测网络连接状态private function beginOrShowRecVideo():void{_netConnection new NetConnection();_netConnection.addEventListener(NetStatusEvent.NET_STATUS,__onNetStatusHandler);_netConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,__onSecurityErrorHandler);_netConnection.connect(_videoServerURL);}//录制视频向服务器传送视频及音频流private function beginRecConnectStream():void{if(_localVideo ! null){_localVideo.clear();t_flv_video.removeChild(_localVideo);_localVideo new Video();_localVideo.width 320;_localVideo.height 240;_localVideo.attachCamera(_camera);t_flv_video.addChild(_localVideo);}_outStream new NetStream(_netConnection);_outStream.attachCamera(_camera);_outStream.attachAudio(_mic);_outStream.publish(testVideo,record);}//播放视频private function showRecConnectStream():void{_inStream new NetStream(_netConnection);_inStream.addEventListener(NetStatusEvent.NET_STATUS,__onNetStatusHandler);_inStream.addEventListener(AsyncErrorEvent.ASYNC_ERROR,__onStreamErrorHandler);//定义onMetaData获取视频相关数据var customClient:Object new Object();customClient.onMetaData function(metadata:Object):void{_duration metadata.duration; //获取视频持续时间t_hs_control.maximum _duration; //设置播放进度条最大值}_inStream.client customClient;//删除原_localVideo便于在录制和播放视频之间切换_localVideo.clear();t_flv_video.removeChild(_localVideo);_localVideo new Video();_localVideo.width 320;_localVideo.height 240;_localVideo.attachNetStream(_inStream);_inStream.play(testVideo);t_flv_video.addChild(_localVideo);}//播放按钮点击后事件播放视频同时分析是否播放来调整BUTTON上的标签显示为播放或者暂停//并监听播放器private function flvplay(event:Event):void{t_hs_control.enabledtrue;t_btn_stop.enabled true;t_btn_rec.enabled false;if(!isplaying){isplaying true;beginOrShowRecVideo();}else{_inStream.togglePause(); //自动在停止和播放之间切换}if(isplaying){if(ispauseing){t_btn_play.label播放}else {t_btn_play.label暂停}ispauseing !ispauseing;}addEventListener(Event.ENTER_FRAME,__onEnterFrame);}//停止按钮和视频播放完毕//重设一些值变量、按钮enabled值等private function resetSomeParam():void{_inStream.close();t_btn_play.label 播放;t_lbl_playtime.text 0:00 / formatTimes(_duration);t_hs_control.value 0;isplaying false;ispauseing false;t_hs_control.enabledfalse;t_btn_rec.enabled true;t_btn_stop.enabled false;}//停止播放按钮点击事件停止视频同时调整相关BUTTON上的标签private function flvStop(event:Event):void{resetSomeParam();removeEventListener(Event.ENTER_FRAME,__onEnterFrame);}//拉动进度条private function thumbPress(event:SliderEvent):void{_inStream.togglePause();removeEventListener(Event.ENTER_FRAME,__onEnterFrame);}//进度条改变后得到的值赋予PLAYPOSITIONprivate function thumbChanges(event:SliderEvent):void{playPosition t_hs_control.value;}//放开进度条再把PLAYPOSITION的值发给播放器private function thumbRelease(event:SliderEvent):void{_inStream.seek(playPosition);_inStream.togglePause();addEventListener(Event.ENTER_FRAME,__onEnterFrame);}//声音音量控制private function sound_thumbChanges(event:SliderEvent):void{soundPosition hs_sound.value;}private function sound_thumbRelease(event:SliderEvent):void{t_flv_video.volume soundPosition;}//格式化时间private function formatTimes(value:int):String{var result:String (value % 60).toString();if (result.length 1){result Math.floor(value / 60).toString() :0 result;} else {result Math.floor(value / 60).toString() : result;}return result;}//录制按钮点击后事件录制视频同时分析是否播放来调整BUTTON上的标签显示为开始录制或者停止录制//并监听播放器private function recVideo(event:MouseEvent):void{if(!isrecing) //开始录制{isrecing true;t_btn_rec.label 停止录制;t_btn_play.enabled false;t_btn_save.enabled false;t_lbl_rec.visible true;beginOrShowRecVideo();}else //停止录制{isrecing false;t_btn_rec.label 开始录制;t_btn_play.enabled true;t_btn_save.enabled true;t_lbl_rec.visible false;_outStream.close();}}//检测摄像头权限事件private function __onStatusHandler(event:StatusEvent):void{if(!_camera.muted){t_btn_rec.enabled true;}else{trace(错误无法链接到活动摄像头)}_camera.removeEventListener(StatusEvent.STATUS,__onStatusHandler);}//网络链接事件//如果网络连接成功开始录制或观看视频private function __onNetStatusHandler(event:NetStatusEvent):void{switch (event.info.code){case NetConnection.Connect.Success:if(isrecing){beginRecConnectStream();}else{showRecConnectStream();}break;case NetConnection.Connect.Failed:trace(连接失败);break;case NetStream.Play.StreamNotFound:trace(Stream not found: event);break;}}private function __onSecurityErrorHandler(event:SecurityErrorEvent):void{trace(securityErrorHandler event);}private function __onStreamErrorHandler(event:AsyncErrorEvent):void{trace(event.error.message);}//播放视频实时事件//实时更改播放进度条值和播放时间值当视频播放完成时删除实时侦听事件并重新设置一些初始值private function __onEnterFrame(event:Event):void{if(_duration 0 _inStream.time 0){t_hs_control.value _inStream.time;t_lbl_playtime.text formatTimes(_inStream.time) / formatTimes(_duration);}if(_inStream.time _duration){removeEventListener(Event.ENTER_FRAME,__onEnterFrame);resetSomeParam();}}]]/mx:Script!--通过HTTPSERVICE来分析XML然后得出RESULT结果的反馈在SCRIPT里--!--此为读取XML扩展内容mx:HTTPService idvideoserver urlassets/videos.xml resultreadXml(event) /--!--主要的视频播放窗口 设置ID为FLVVIDEO这个很重要其他坐标可以随自己喜欢 --mx:Panel x12 y10 width342 height282 layoutabsolutemx:VideoDisplay idt_flv_video x1 y1 width320 height240/mx:Label x243.5 y6 text正在录制中… idt_lbl_rec color#666666 fontSize12//mx:Panel!--播放器的播放进度条用FLEX自带的HSLIDER来表现播放进度同时可以拖动影片--mx:HSlider idt_hs_control x12 y296 minimum0thumbPressthumbPress(event)thumbReleasethumbRelease(event)changethumbChanges(event) /!--播放器声音控制--mx:HSlider idhs_sound x260 y295 width80minimum0 maximum1thumbReleasesound_thumbRelease(event)changesound_thumbChanges(event)value{t_flv_video.volume} /!--播放按钮根据是否在播放按钮显示为播放 或者 暂停--mx:Button idt_btn_play x22 y320 clickflvplay(event) label播放 fontSize12 /!--播放按钮停止播放影片--mx:Button idt_btn_stop label停止 x85 y320clickflvStop(event) fontSize12 enabledtrue/!--时间显示--mx:Label x170 y300 idt_lbl_playtimetext0:00 / 0:00 color#ffffff/!--录制按钮根据是否在录制按钮显示为开始录制 或者 停止录制--mx:Button x210 y320 label开始录制 clickrecVideo(event) fontSize12 idt_btn_rec/!--保存视频按钮--mx:Button x299 y320 label保存 fontSize12 idt_btn_save enabledtrue//mx:Application复制代码第五步编写同步播放的程序VideoPlayer这个也是从网上扒的原文地址http://www.cnblogs.com/wuhenke/archive/2009/11/03/1595436.html 我修改了服务器地址由于源码是flex4的所以我修改成了Flex3。我的代码如下videoConfig.xmlView Code?xml version1.0?videoConfig item rtmpUrlrtmp://192.168.2.105/tests//rtmpUrl filmNametestVideo.flv/filmName /item/videoConfig复制代码VideoEvent.asView Codepackage{ import flash.events.EventDispatcher;public class VideoEvent extends EventDispatcher {// 静态常量定义事件类型 public static const VidoPlay:StringVideoPlay;// 静态实例 private static var _instance:VideoEvent;public static function getInstance():VideoEvent {if(_instancenull) _instancenew VideoEvent();return _instance; } }}复制代码VideoPlayer.mxmlView Code?xml version1.0 encodingutf-8?mx:Application xmlns:mxhttp://www.adobe.com/2006/mxml layoutabsolute creationCompleteinit() width366 height350 !-- Place non-visual elements (e.g., services, value objects) here -- !--mx:HTTPService idmyService urlvideoConfig.xml resultresultHandler(event)/-- !-- Place non-visual elements (e.g., services, value objects) here -- mx:HTTPService idmyService urlvideoConfig.xml resultresultHandler(event)/ mx:Script ![CDATA[ import mx.rpc.events.ResultEvent; import mx.controls.Alert;//定义视频播放事件监听对象 public var instance:VideoEventVideoEvent.getInstance(); private var filmSource:String;//IronMan.flv private function init():void {//发送读取配置的请求 myService.send();//定义视频播放事件监听 instance.addEventListener(VideoPlay,playVideoHandler); }//视频监听的处理 private function playVideoHandler(event:Event):void {var myVideo:SharedObject;//将播放头置于视频开始处 myVideoSharedObject.getLocal(videoCookie);var vName:StringmyVideo.data.vName;//播放选中的视频 film.sourcefilmSourcevName; }private function changeSource():void {var myVideo:SharedObject;//将播放头置于视频开始处 myVideoSharedObject.getLocal(videoCookie);//将视频的文件名称存放到共享文件里 myVideo.data.vNameDarkKnight.flv;//一定要先存放VCODE到共享对象里再分发事件 instance.dispatchEvent(new Event(VideoPlay)); }//读取配置文件 private function resultHandler(event:ResultEvent):void {//获取流媒体服务器 地址 filmSourceevent.result.videoConfig.item.rtmpUrl;//获取流媒体文件名 var filmName:Stringevent.result.videoConfig.item.filmName;//获取流媒体完整路径 film.sourcefilmSourcefilmName; } ]] /mx:Script mx:VideoDisplay width396 height294 idfilm /mx:VideoDisplaymx:Button label更换播放源 buttonDownchangeSource() x8 y301//mx:Application复制代码第六步运行效果图如下左图是录像右图是播放。注意本文中的程序在现实运行中播放的画面比实时录像的画面要延时几秒钟谁有更好的解决方案请不吝赐教谢谢