使用FLASH做在线录音(Flash Media Server)
yoken
阅读:1796
2007-10-15 01:27:00
评论:0
import flash.geom.Rectangle;
var name_time:String = "";
//
fsm_err._visible = true;
fsm_err.useHandCursor=false;
Graphspeed = 20;
TotalGraphSeconds = (1000/Graphspeed)*myMictime;
//
myGraphBgColor = new Color(myGraph.bg);
myGraphBgColor.setRGB(OutColor);
myBgColor = new Color(myBg);
myBgColor.setRGB(MicColor);
//
muButton_play_Color = new Color(myButton.myPlay.bg);
muButton_play_Color.setRGB(ButtonColor);
muButton_save_Color = new Color(myButton.mySave.bg);
muButton_save_Color.setRGB(ButtonColor);
//
myBg._x = myBg._y=0;
var myBggrid:Rectangle = new Rectangle(40, 40, 14, 14);
myBg.scale9Grid = myBggrid;
myBg._width = fsm_err._width=myWidth;
myBg._height = fsm_err._height=myHeight;
myButton._x = myWidth-20-myButton._width;
myButton._y = myGraph._y=15;
myGraph._x = 30;
var myGraphgrid:Rectangle = new Rectangle(5, 5, 17, 17);
myGraph.bg.scale9Grid = myGraphgrid;
myGraph.bg._width = myWidth-60-myButton._width;
myGraph.bg._height = myButton._height;
myGraph.totalBar._x = 5;
myGraph.totalBar._y = 1;
myGraph.totalBar._width = myGraph.bg._width-10;
GraphHieght = (myGraph._height-20)/2;
myGraph.micBar._visible = myGraph.playBar._visible=false;
myGraph.micBar._x = myGraph.playBar._x=5;
myGraph.micBar._y = myGraph.playBar._y=1;
myGraph.micBar._height = myGraph.playBar._height=myGraph.totalBar._height=GraphHieght*2-2;
//
myGraph.myTime._x = myGraph.bg._width-myGraph.myTime._width;
myGraph.myTime._y = myGraph.bg._height-myGraph.myTime._height;
newConnection = new NetConnection();
//newConnection.connect("rtmp://www.evoca.com/liveCast");
newConnection.connect(myFms);
newConnection.onStatus = function(info) {
if (info.code == "NetConnection.Connect.Success") {
//
fsm_err._visible = false;
//
newNetstream = new NetStream(newConnection);
myMic = Microphone.get();
myMic.setRate(44);
myMic.setGain(50);
myMic.setSilenceLevel(0, 0);
//建立流、获取麦克风
} else {
fsm_err._visible = true;
}
};
//连接FMS到服务器
myButton.recordMC.onRelease = function() {
if (this._currentframe == 1) {
this.gotoAndStop(2);
//
myButton.myPlay.txt.text = "播放";
//
recordRecording();
//
myGraph.playBar._visible = false;
} else {
recordStop();
}
};
myButton.myPlay.onRelease = function() {
clearInterval(myPlayRecordGraph);
if (myMic.muted != true) {
if (this.txt.text == "播放") {
this.txt.text = "停止";
recordStop();
//
newNetstream = new NetStream(newConnection);
newNetstream.play(name_time);
//
//
playSeconds = 0;
myPlayRecordGraph = setInterval(playGraph, Graphspeed);
} else {
this.txt.text = "播放";
newNetstream.pause();
}
}
};
function recordStop() {
myButton.recordMC.gotoAndStop(1);
clearInterval(myRecordGraph);
}
function playGraph() {
playSeconds++;
if (playSeconds<=playGraphSeconds) {
myGraph.playBar._visible = true;
play_x = (myGraph._width-10)*(playSeconds/TotalGraphSeconds)+5;
myGraph.playBar._width = play_x-5;
} else {
myButton.myPlay.txt.text = "播放";
clearInterval(myPlayRecordGraph);
}
}
function recordRecording() {
var now = new Date();
name_time = now.getTime().toString();
newNetstream.attachAudio(myMic);
newNetstream.publish(name_time, "record");
//
playGraphSeconds = 0;
//
myGraph.line.clear();
//
clearInterval(myPlayRecordGraph);
//
myRecordGraph = setInterval(updateGraph, Graphspeed);
}
function updateGraph() {
if (myMic.muted != true) {
playGraphSeconds++;
myGraph.micBar._visible = true;
myGraph.myTime.txt.text = "已录制"+Math.floor(playGraphSeconds/(1000/Graphspeed))+"秒";
if (playGraphSeconds<=TotalGraphSeconds) {
line_x = (myGraph._width-10)*(playGraphSeconds/TotalGraphSeconds)+5;
myGraph.micBar._width = line_x-5;
with (myGraph.line) {
lineStyle(1, GraphColor, 60);
moveTo(line_x, GraphHieght+(((myMic.activityLevel-45))/55)*(GraphHieght-2));
lineTo(line_x, GraphHieght-(((myMic.activityLevel-45))/55)*(GraphHieght-2));
}
} else {
myButton.recordMC.gotoAndStop(1);
clearInterval(myRecordGraph);
}
}
// end if
}
转载保留链接!网址:https://80920140.com/post/41.html
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源; 2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任; 3.作者投稿可能会经我们编辑修改或补充。
发表评论