呃..閑來無事,不知道做什么好.想來想去就打算寫個在線錄視頻的教程吧.
這程序?qū)懙耐唵蔚?.不懂的呢,可以參考下..高手就別笑我了.嘿嘿.
準(zhǔn)備工具:
Flash Media Server..
Flash 8 && Flash 8 Player (-______-)
一個攝像頭,一個麥克.
打開FLASH,新建一個FLASH文檔.
CTRL + L調(diào)出庫..在庫的右上角有個三角,點(diǎn)一下.然后選擇"新建視頻元件";
命名為: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);
//設(shè)置帶寬和質(zhì)量;
var my_mic:Microphone = Microphone.get ();
//獲得MIC;
my_ns.attachVideo (my_cam);
my_ns.attachAudio (my_mic);
//將攝像頭圖象和MIC聲音裝載到流.
video_p._visible = false;
//將播放窗口設(shè)置為不可見.
my_nc.onStatus = function (thisObj:Object)
{
//trace (thisObj.code);
if (thisObj.code == "NetConnection.Connect.Success")
{
RecordStop ("空閑中");
//執(zhí)行錄制停止方法.并將狀態(tài)設(shè)置為空閑
}
else
{
trace ("錯誤:服務(wù)器未啟動或URI輸入錯誤.");
}
}
//onStatus這里是指服務(wù)器的連接狀態(tài).
function Record ()
{
video_r._visible = true;
//將錄制窗口設(shè)為可見.
video_p._visible = false;
//播放窗口設(shè)置為不可見.
my_ns.publish (videoName, "record");
//關(guān)鍵就在這句了.寫了這么多全圍繞它來的.record為錄制.
StreamInfo ("NowRecord");
//執(zhí)行StreamInfo方法,并將參數(shù)設(shè)置為NowRecord;
btn_pr.btn_text.text = "停止";
//按鈕文字:停止.
RecordInterval = setInterval (RecordTime, 1000);
//統(tǒng)計錄制時間.
}
//方法:錄制.
var timeNum:Number = 0;
//錄制時間.
function RecordTime ()
{
timeNum ++;
txt_status.text = "正在錄制" + " " + "時間:" + Math.floor (timeNum / 60) + "分" + (timeNum % 60) + "秒";
}
//方法:錄制時間統(tǒng)計.
function RecordStop (__status:String)
{
//__status是當(dāng)前狀態(tài)文字.
txt_status.text = "當(dāng)前狀態(tài):" + __status;
btn_pr.btn_text.text = "錄制";
StreamInfo ("NowStop");
//執(zhí)行StreamInfo方法..并將參數(shù)設(shè)置為NowStop;
clearInterval (RecordInterval);
timeNum = 0;
//不錄了..要把統(tǒng)計時間清空.
if (__status == "錄制完成")
{
Finished ();
}
//這個應(yīng)該不用偶說了..
}
//方法:空閑或錄制完成.
function Finished ()
{
my_ns.close();
//完成了..就要關(guān)閉錄制.
var thisObj = this;
var FinishAlert:MovieClip = _root.attachMovie ("Alert", "FinishAlert", 100);
//這個是一個彈出框.具體看庫里的MC:Alert.
with (FinishAlert)
{
alertTitle.html = true;
alertTitle.htmlText = "<b>" + "錄制完成!" + "</b>";
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;
//把按鈕設(shè)為不可點(diǎn).
}
//方法:錄制完成.
function closeAlert (__alert:MovieClip)
{
btn_pr.enabled = true;
unloadMovie (__alert);
}
//關(guān)閉那個Alert用的.
function StreamInfo (__status:String)
{
btn_pr.onRelease = function ()
{
if (__status == "NowRecord")
{
RecordStop ("錄制完成");
}
else if (__status == "NowStop")
{
Record ();
}
else if (__status == "NowPlay")
{
Record ();
}
}
}
//嘿嘿..如果把上面的仔細(xì)看了的話這個就不用我說了吧.^_^
function PlayVideo ()
{
txt_status.text = "當(dāng)前狀態(tài):" + "正在播放...";
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 = "當(dāng)前狀態(tài):" + "播放完成...";
}
}
//流狀態(tài)信息...詳細(xì)的請自己 trace (PlayInfo.code);
}
//方法:播放視頻.
//需要注意的是用FMS播放的時候不用寫路徑.因為FMS錄的視頻直接存在FMS默認(rèn)的流文件目錄里了.
//錄的視頻的存放路徑:FMS安裝目錄:/application/站點(diǎn)/streams/_definst_
如果上面看個差不多了可以自己動手做一下了.祝大家好運(yùn) (By:KeeRula)(:
具體MC這一類請看FLA文件.
源文件: 點(diǎn)此下載.