代码
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 thisObj = 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);
}
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 thisObj = 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);
}