准备工具:
Flash Media Server..
Flash 8 && Flash 8 Player
一个摄像头,一个麦克.
打开FLASH,新建一个FLASH文档.
CTRL + L调出库..在库的右上角有个三角,点一下.然后选择"新建视频元件";
命名为:video
在主场景里新建2个图层,一个名字叫 video_record,另一个叫video_play;
将库里的视频元件分别拖到这2个图层中.起名字叫video_r和video_p.video_r是用来录视频的.video_p是用来放视频的.
(下面起新建MC啊,或命名一类的我就不写了.只做程序介绍.如果连MC命名都不知道的话相信也看不懂这教程.大家见谅 :)
程序部分:
var server_uri:String = "rtmp://localhost/tensharp";
//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 ();
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);
//统计录制时间.
}
//方法:录制.
var timeNum:Number = 0;
//录制时间.
function RecordTime ()
{
timeNum ++;
txt_status.text = "正在录制" + " " + "时间:" + Math.floor (timeNum / 60) + "分" + (timeNum % 60) + "秒";
}
//方法:录制时间统计.
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);
//统计录制时间.
}
//方法:录制.
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用的.
教程:教你用FMS在线录制视频
最新推荐文章于 2022-04-02 13:00:00 发布