flash在线录音

1893人阅读 评论(3) 收藏 举报

轉:http://www.332500.net/post/41.htm

源码:
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                                                                            
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值