[AS3]as3处理FMS的视频录像(代码实例)
[AS3]as3处理FMS的视频录像(代码实例),as3录像,as3处理FMS,as3与fms
[AS3]as3处理FMS的视频录像(代码实例)
- var mic:Microphone = Microphone.getMicrophone();
- mic.setUseEchoSuppression(true);
- mic.setLoopBack(true);
- //但那只是得到MIC的声音流并回放到音箱上,音频数据是没法得到的~~
- //如果不用NetConnection和NetStream的话
- //极酷播放器提示:下面是使用FMS保存录像
- var server_uri:String = "rtmp://localhost/test";
- //FMS地址;
- var videoName:String = "KeeRula";
- //视频名.
- var my_nc:NetConnection = new NetConnection();
- //新建一个连接对象,用来连接FMS;
- my_nc.connect(server_uri);
- //连接FMS;
- var my_ns:NetStream = new NetStream(my_nc);
- //新建流,用来捕获和播放视频;
- var my_cam:Camera = Camera.get(1);
- video_r.attachVideo(my_cam);
- //获得慑像头,并将摄像头获取的视频载入到video_r里.
- my_cam.setQuality(1024, 90);
- //设置带宽和质量;
- var my_mic:Microphone = Microphone.get();
- //获得MIC;
- my_ns.attachVideo(my_cam);
- my_ns.attachAudio(my_mic);
- //将摄像头图象和MIC声音装载到流.
- video_p._visible = false;
- //将播放窗口设置为不可见.
- my_nc.onStatus = function(thisObj:Object)
- {
- //trace (thisObj.code);
- if (thisObj.code == "NetConnection.Connect.Success")
- {
- RecordStop("空闲中");
- //执行录制停止方法.并将状态设置为空闲
- }
- else
- {
- trace("错误:服务器未启动或URI输入错误.");
- }
- };
- //onStatus这里是指服务器的连接状态.
- function Record()
- {
- video_r._visible = true;
- //将录制窗口设为可见.
- video_p._visible = false;
- //播放窗口设置为不可见.
- my_ns.publish(videoName, "record");
- //关键就在这句了.写了这么多全围绕它来的.record为录制.
- StreamInfo("NowRecord");
- //执行StreamInfo方法,并将参数设置为NowRecord;
- btn_pr.btn_text.text = "停止";
- //按钮文字:停止.
- RecordInterval = setInterval(RecordTime, 1000);
- //统计录制时间.
- }
- Record()
- //方法:录制.
- var timeNum:Number = 0;
- //录制时间.
- function RecordTime()
- {
- timeNum++;
- txt_status.text = "正在录制" + " " + "时间:" + Math.floor(timeNum / 60) + "分" + (timeNum % 60) + "秒";
- }
- //方法:录制时间统计.
- function RecordStop(__status:String)
- {
- //__status是当前状态文字.
- txt_status.text = "当前状态:" + __status;
- btn_pr.btn_text.text = "录制";
- StreamInfo("NowStop");
- //执行StreamInfo方法..并将参数设置为NowStop;
- clearInterval(RecordInterval);
- timeNum = 0;
- //不录了..要把统计时间清空.
- if (__status == "录制完成")
- {
- Finished();
- }
- //这个应该不用偶说了..
- }
- //方法:空闲或录制完成.
- function Finished()
- {
- my_ns.close();
- //完成了..就要关闭录制.
- var thisthisObj = this;
- var FinishAlert:MovieClip = _root.attachMovie("Alert", "FinishAlert", 100);
- //这个是一个弹出框.具体看库里的MC:Alert.
- with (FinishAlert)
- {
- alertTitle.HTML = true;
- alertTitle.HTMLText = "" + "录制完成!" + "";
- info.text = "录制完成..请选择下一步操作.";
- _x = video_r._x + (video_r._width - _width) / 2;
- _y = video_r._y + (video_r._height - _height) / 2;
- btn_sub.btn_txt.text = "播放";
- btn_cln.btn_txt.text = "重录";
- btn_sub.onRelease = function()
- {
- thisObj.PlayVideo();
- thisObj.closeAlert(FinishAlert);
- };
- btn_cln.onRelease = function()
- {
- thisObj.Record();
- thisObj.closeAlert(FinishAlert);
- };
- closed.onRelease = function()
- {
- thisObj.closeAlert(FinishAlert);
- };
- }
- btn_pr.enabled = false;
- //把按钮设为不可点.
- }
- //方法:录制完成.
- function closeAlert(__alert:MovieClip)
- {
- btn_pr.enabled = true;
- unloadMovie(__alert);
- }
- //关闭那个Alert用的.
- function StreamInfo(__status:String)
- {
- btn_pr.onRelease = function()
- {
- if (__status == "NowRecord")
- {
- RecordStop("录制完成");
- }
- else if (__status == "NowStop")
- {
- Record();
- }
- else if (__status == "NowPlay")
- {
- Record();
- }
- };
- }
- //嘿嘿..如果把上面的仔细看了的话这个就不用我说了吧.^_^
- function PlayVideo()
- {
- txt_status.text = "当前状态:" + "正在播放...";
- StreamInfo("NowPlay");
- video_r._visible = false;
- video_p._visible = true;
- video_p.attachVideo(my_ns);
- //将视频载到播放窗口中.
- my_ns.play(videoName);
- //开始播放.
- btn_pr.btn_text.text = "重录";
- my_ns.onStatus = function(PlayInfo)
- {
- if (PlayInfo.code == "NetStream.Play.Stop")
- {
- my_ns.seek(0);
- my_ns.pause();
- txt_status.text = "当前状态:" + "播放完成...";
- }
- };
- //流状态信息...详细的请自己 trace (PlayInfo.code);
- }
热门文章推荐
- [FMS]Adobe FMS产品(Adobe Flash Media Server)使用介绍(组图)
- [FMS]Flash Media Server之教程附示例代码
- [RTMP]国产RTMP/HLS直播服务器simple-rtmp-server
- [WOWZA]用wowza流媒体服务器发布和播放直播流(RTMP)
- [RTMP]又一款rtmp类的服务器openrtmfp流媒体服务器
- [RTMP]adobe之FMS视频直播解决方案流程介绍(组图)
- [RTMP协议]实时消息传输协议 (RTMP) 常识性介绍
- [FMS]Adobe的Flash Media Server服务器(FMS服务器)安装
请稍候...