首页 新闻 会员 周边

我用flex+fms做录音功能,总是录不进去,还请各位高手指教

0
悬赏园豆:50 [已关闭问题] 关闭于 2011-09-27 10:53

我用flex+fms做录音功能,总是录不进去,还请各位高手指教,下面是我的代码

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    width="433" height="286" creationComplete="init()" fontSize="12" layout="absolute">
 <mx:Script>
  import mx.controls.Alert;
        private var conn:NetConnection;//连接对象
  private var stream:NetStream;//流对象
  private var path:String="rtmp://localhost/myApp";
  private var mic:Microphone;//麦对象
  private var cam:Camera;//视频对象
    
  private function init():void
  {
  
   conn = new NetConnection();
   conn.connect(path); 
   conn.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
      play.addEventListener(MouseEvent.CLICK,playFlv);
   puse.addEventListener(MouseEvent.CLICK,puseFlv);
   record.addEventListener(MouseEvent.CLICK,recordFlv);
   stop.addEventListener(MouseEvent.CLICK,stopFlv);
   replay.addEventListener(MouseEvent.CLICK,replayFlv);   
  
           initMedia();
  
   
  }
  
  private function initMedia():void
  {
    mic=Microphone.getMicrophone();//初始化麦 
  
   if(mic!=null)
   {
    mic.gain=85;
    mic.rate=10;
    mic.setUseEchoSuppression(true);
    mic.setLoopBack(true);
    mic.setSilenceLevel(0,-1);
   
   }
   else
   {
      status.text="请添加麦克风!";
   }
    cam=Camera.getCamera();
    if(cam!=null)//判断有没有摄像
    {
     cam.setMode(300,180,15,true);
     cam.setQuality(0,100);
     display.attachCamera(cam);
    
    }
       
  }
  
  private function netStatusHandler(evt:NetStatusEvent):void
  {     
   if(evt.info.code=="NetConnection.Connect.Success" )
   {
    status.text="已连接!";
    var me:MicrophoneExample = new MicrophoneExample();//弹出设置设备提示框
    stream = new NetStream(conn);
    
   }
   else
   {
    status.text="连接失败!";
   

   }
  
  }
  
  private function playFlv(evt:MouseEvent):void
  {
   status.text="正在播放!";
   stream.play(path+"/001");
   status.text=stream.bufferLength.toString();
  }
  private function stopFlv(evt:MouseEvent):void
  {
   status.text="已停止!";
   stream.close();
  }
  private function replayFlv(evt:MouseEvent):void
  {
   status.text="继续录制!";
  }
  private function recordFlv(evt:MouseEvent):void
  {
   status.text="正在录制!";
      stream.attachAudio(mic);
   stream.attachCamera(cam);
   
      stream.publish("001","record");
  }
  private function puseFlv(evt:MouseEvent):void
  {
   status.text="已暂停!";
   stream.pause();
  }
    </mx:Script>
 <mx:VideoDisplay id="display" x="17" y="13" width="382" height="194"/>
 <mx:Label x="16" y="216" text="当前状态:"/><mx:Label id="status" x="94" y="216" text="未连接!"/>
 <mx:Button id="record" x="329" y="240" label="录音" />
 <mx:Button id="puse" x="96" y="240" label="暂停"/>
 <mx:Button id="play" x="18" y="240" label="播放"/>
 <mx:Button id="stop" x="253" y="240" label="停止"/>
 <mx:Button id="replay" x="176" y="240" label="继续"/>
 </mx:Application>

 附:麦克正常,fms也可以连通。

徐驰的主页 徐驰 | 初学一级 | 园豆:30
提问于:2011-09-02 14:48
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册