12 Replies Latest reply on Jun 6, 2007 4:03 AM by scorpion219

    Record microphone sound

    scorpion219
      Hi there,
      I am trying to capture and record my microphone sound with Flex 2. How can I achieve this?

      Thanks
        • 1. Re: Record microphone sound
          chris.huston.t10 Level 3
          I use Flash Media Server to record user audio with my Flex 2 applications. It works well but becomes quite expensive if you have more than 10 simultaneous users. The audio is captured to the server, not locally with this method. I don't think Flex can capture local audio, if that is what you need.

          Vygo
          • 2. Re: Record microphone sound
            scorpion219 Level 1
            Thank you for your valuable answer, I was just reviewing Media server. I was wondering the integration between Media Server and Flex. In particular case is it possible to re-use a Media server component as a component in Flex? Any ideas on this?
            Thanks and regards,
            Savas Duvan
            • 3. Re: Record microphone sound
              JabbyPandaUA Level 3
              Masamune was right, you have to use server side solution to store your sound.

              It can be Flash Media Server or it can be Red5 as well.

              Example of Flash Media Server and Flex 2 working together:
              http://thanksmister.com/?p=26
              • 4. Re: Record microphone sound
                scorpion219 Level 1
                Hi I have installed Media Server, read some shipped documentation but could not find any examples on how to capture/record and publish microphone sound
                Do you gents have some examples on this?

                Thanks
                • 6. Re: Record microphone sound
                  scorpion219 Level 1
                  I have created a folder C:\Program Files\Macromedia\Flash Media Server 2\applications\my_app
                  And have verified from FMS console that it is registered.
                  I havent touched any config files of FMS

                  When I run the below simple snippet

                  1. var nc:NetConnection = new NetConnection();
                  2. nc.connect("rtmp:/my_app");
                  3. var ns:NetStream = new NetStream(nc);

                  The below error is thrown at line 3
                  ArgumentError: Error #2126: NetConnection object must be connected.

                  The strange thing is that a connection is added when I look to the applications tab of the FMS console.

                  Any help is appreciated

                  • 7. Re: Record microphone sound
                    chris.huston.t10 Level 3
                    Here is the basic code that I use to establish a connection and record user audio to my Flash Media Server:

                    NetConnection.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;
                    SharedObject.defaultObjectEncoding = flash.net.ObjectEncoding.AMF0;

                    private var nc:NetConnection;

                    private function init_nc():void {
                    nc = new NetConnection();
                    nc.client = this;
                    nc.addEventListener(NetStatusEvent.NET_STATUS, netStatus);
                    nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR , sync_error);
                    nc.connect("rtmp:/my_app");
                    }

                    private function sync_error(event:AsyncErrorEvent):void {
                    Alert.show("sync error = " + event.error);
                    }

                    private function netStatus(event:NetStatusEvent):void {
                    var info:Object = event.info;
                    if (info.code == "NetConnection.Connect.Success") {
                    trace("Successful connection");
                    }
                    }

                    //The following code is used for recording. Set a click event to call the record_audio function
                    private var mic:Microphone;
                    private var stream:NetStream;
                    private function record_audio():void {
                    if (mic != null) {
                    if (stream != null) {
                    stream.close();
                    }
                    stream = new NetStream(nc);
                    stream.attachAudio(mic);
                    stream.publish("file name to record to", "record");
                    } else {
                    mic = Microphone.getMicrophone();
                    Security.showSettings(SecurityPanel.PRIVACY);
                    mic.rate = 22;
                    mic.setUseEchoSuppression(true);
                    }
                    }

                    private function stop_record(evt:MouseEvent=null):void {
                    if (stream != null) {
                    stream.close();
                    stream = null;
                    }
                    }

                    Vygo
                    • 8. Re: Record microphone sound
                      scorpion219 Level 1
                      Thank you for your valuable feedback, it worked. I can record a sound from my mic, but I have to click twice to the record button to start recording.

                      I assume that the files recorded are flv files, can I record them as wav files?

                      And how to play a recording which is saved on the server.

                      I have tried:
                      stream = new NetStream(nc);
                      stream.play("MySavedRecording");

                      Well I hear my recording but it throws some ArgumentError's.
                      • 9. Re: Record microphone sound
                        JabbyPandaUA Level 3
                        Hi,

                        AFAIK, No you cannot save your sound as WAV, only as FLV, that's limitation infringed by file format licensing
                        • 10. Re: Record microphone sound
                          scorpion219 Level 1
                          Any snippets on how to play a recording which is saved on the server.

                          I have tried:
                          stream = new NetStream(nc);
                          stream.play("MySavedRecording");

                          Well I hear my recording but it throws some ArgumentError's.
                          • 11. Re: Record microphone sound
                            chris.huston.t10 Level 3
                            Here is some code to play a recorded flv file on a FMS server:

                            public function onPlayStatus(info:Object):void {
                            trace(info.code);
                            }

                            public function onMetaData(info:Object):void {
                            trace("metadata: duration=" + info.duration);
                            }

                            private function play_fms_recording(evt:MouseEvent):void {
                            if (stream != null) {
                            stream.close();
                            }
                            stream = new NetStream(nc);
                            stream.addEventListener(NetStatusEvent.NET_STATUS, play_fms_status);
                            stream.client = this;
                            stream.play("saved_recording");
                            }

                            private function play_fms_status(evt:NetStatusEvent):void {
                            evt.currentTarget.removeEventListener(NetStatusEvent.NET_STATUS, play_fms_status);
                            if (evt.info.code == "NetStream.Play.StreamNotFound") {
                            Alert.show("There is no recording to play.");
                            }
                            }

                            Vygo
                            • 12. Re: Record microphone sound
                              scorpion219 Level 1
                              OK, my final question: How do I get a list of FLV files stored on my FMS/my_app