Skip to main content
October 19, 2009
Question

Can't record audio...

  • October 19, 2009
  • 1 reply
  • 526 views

I don't seem to be able to record audio with my microphone to flash media server. Every time I try a 1kb flv file is made, but it is empty when I try to play it back, and basically doesn't work. I didn't install apache server when I installed media server because I already have it installed. Could this make a difference? My code is below. Any ideas?


package {

    import flash.display.MovieClip;
    import flash.net.NetConnection;
    import flash.events.NetStatusEvent;
    import flash.events.MouseEvent;
    import flash.net.*;
    import flash.media.Microphone;
    import flash.system.*;
   
    public class HelloServer extends MovieClip {
             
      private var nc:NetConnection;
      var myNS:NetStream;
      var mic:Microphone;
      /*
       *  Constructor.
       */
      public function HelloServer() {
            // register listeners for mouse clicks on the two buttons
            connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
            closeBtn.addEventListener(MouseEvent.CLICK, closeHandler);
      }
     
      //Once Connected
      public function connected():void{
       
        myNS = new NetStream(nc);
        myNS.attachAudio(mic);
        myNS.publish("alex" + Math.random(), "record"); 
      }
     
     /*
      *  Connect to the server.
      */
     public function connectHandler(event:MouseEvent):void {
             mic = Microphone.getMicrophone();
            //Security.showSettings(SecurityPanel.PRIVACY);
            mic.rate = 22;
            mic.setUseEchoSuppression(true);
           
            trace("Okay, let's connect now");
             nc = new NetConnection();
            nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            nc.connect("rtmp://localhost/HelloServer");
     }
    
    
     /*
      *  Disconnect from the server.
      */
     public function closeHandler(event:MouseEvent):void {
            trace("Now we're disconnecting");
            myNS.close();
            nc.close();
     }
    
    
     /*
      *  Handle events relating to the server connection.
      */
     public function netStatusHandler(event:NetStatusEvent):void {
            trace("connected is: " + nc.connected);
            trace("event.info.level: " + event.info.level);
            trace("event.info.code: " + event.info.code);
           
            switch (event.info.code)
            {
                case "NetConnection.Connect.Success":
                    trace("Congratulations! you're connected" + "\n");
                    connected();
                    break;
                case "NetConnection.Connect.Rejected":
                    trace ("Oops! the connection was rejected" + "\n");
                    break;
                case "NetConnection.Connect.Closed":
                    trace("Thanks! the connection has been closed" + "\n");
                    break;
           }
     }
   
   
   }
}
   
   
   
   
   
   
   
   
   
   

    This topic has been closed for replies.

    1 reply

    October 19, 2009

    Since FMS is creating the file (which suggests all of your syntax is correct), I'd first confirm that the microphone is actually getting sound into the flashplayer. Try doing the following:

    1. Make sure the appropriate audio source is selected in the flashplayer settings panel

    2. From the FMS admin console, try playing the stream (you may need to add allowDebug=true to the top of your main.asc). Do you hear sound? If not, the flashplayer isn't publishing any audio.