hi
i want to capture voice in flash using flex and fms
this is my source code

FMSConnection.as


// ActionScript file
package sample {
    import flash.net.NetConnection;
    import flash.events.NetStatusEvent;
    import flash.events.SecurityErrorEvent;
    import flash.events.AsyncErrorEvent;
    import flash.events.IOErrorEvent;
    import flash.net.ObjectEncoding;

    [Event(name="connectResult",
type="flash.events.NetStatusEvent")]
    [Event(name="connectFail",
type="flash.events.NetStatusEvent")]
    [Event(name="disconnectResult",
type="flash.events.NetStatusEvent")]

    /*
     * FMSConnection is designed to change the behaviour of
NetConnection in three ways:
     *   1. If close is called a NetConnection.Connect.Closed event is
NOT broadcast.
     *   2. If a connection attempt fails only the first event is
broadcast and not the
     *      following NetConnection.Connect.Closed event.
     *   3. Instead of dispatching one "netStatus" event that must be
interpreted as a successful
     *      failed or closed connection, FMSConnect broadcasts one of
     *      three NetStatusEvents named:
     *         a. connectResult - a successful connection
NetStatusEvent
     *         b. connectFail   - an unsuccessful connection attempt
NetStatusEvent
     *         c. dsconnectResult - when an established connection is
lost
     *
     *   The FMSConnect object still broadcasts netStatus events if
you listen for them.
     *   However, you have the option of doing this instead:
     *      var fmsConnection:FMSConnection = new FMSConnection();
     *      fmsConnection.addEventListener("connectResult",
connectResult);
     *      fmsConnection.addEventListener("connectFail",
connectFail);
     *      fmsConnection.addEventListener("disconnectResult",
disconnectResult);
     *
     *   Depending on how you code this may make connection state
management easier.
     *   As a convenience the state variable currentState is public.
     *
     *   Finally, since FMSConnection listens for its own errors you
don't have to
     *   listen for SecurityErrorEvent or IOErrorEvent events, which
is perhaps not
     *   a good thing...
     */

    public class FMSConnection extends NetConnection {

        static private var _NOT_CONNECTED:Number = 0;
        static private var _CONNECTING:Number = 1;
        static private var _CONNECTED:Number = 2;

        private var _handleCloseEvent:Boolean = true;
        public var currentState:Number = _NOT_CONNECTED;

        function FMSConnection() {
            super();
            addEventListener(NetStatusEvent.NET_STATUS,
handleConnectionStatusEvent);
            addEventListener(SecurityErrorEvent.SECURITY_ERROR,
handleSecurityError);
            addEventListener(AsyncErrorEvent.ASYNC_ERROR,
handleAsyncError);
            addEventListener(IOErrorEvent.IO_ERROR,
handleIOError);
        }

        override public function connect(command:String, ...
arguments):void{
            arguments.unshift(command);
            currentState = _CONNECTING;
            _handleCloseEvent = true;
            super.connect.apply(this, arguments);
        }

        override public function close():void{
            currentState = _NOT_CONNECTED;
            _handleCloseEvent = false;
            super.close();
        }

        public function
handleConnectionStatusEvent(event:NetStatusEvent):void{
            trace("FMSConnection.handleConnectionStatusEvent> " +
event.info.code);

            var codeTokens:Array = event.info.code.split(".");

            // For now ignore Call related events and only process
Connect events:
            if (codeTokens[1] == "Connect"){
                switch (codeTokens[2]){
                    case "Success":
                        _handleCloseEvent = true;
                        currentState = _CONNECTED;
                        dispatchEvent(new
NetStatusEvent("connectResult", false, false, event.info));
                        break;
                    case "Closed":
                        if(_handleCloseEvent) {
                            if(currentState == _CONNECTED){
                                dispatchEvent(new
NetStatusEvent("disconnectResult", false, false, event.info));
                            }
                            else {
                                dispatchEvent(new
NetStatusEvent("connectFail", false, false, event.info));
                            }
                            currentState = _NOT_CONNECTED;
                        }
                        break;
                    default:
                        if(currentState == _CONNECTED){
                            dispatchEvent(new
NetStatusEvent("disconnectResult", false, false, event.info));
                        }
                        else {
                            dispatchEvent(new
NetStatusEvent("connectFail", false, false, event.info));
                        }
                        currentState = _NOT_CONNECTED;
                        _handleCloseEvent= false;
                }
            }
            else if (codeTokens[1] == "Call"){
                var info:Object = event.info;
                for(var p:String in info)
trace("FMSConnection.handleConnectionStatusEvent> " + p + ": " +
info[p]);
            }
        }

        protected function
handleSecurityError(event:SecurityErrorEvent):void{
            trace("FMSConnection.handleSecurityError> " + event.text);
        }

        protected function
handleAsyncError(event:AsyncErrorEvent):void{
            trace("FMSConnection.handleAsyncError> " +
event.error.message);
        }


        protected function handleIOError(event:IOErrorEvent):void{
            trace("FMSConnection.handleIOError> " + event.text);
        }

    }
}



FMSflex.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute">
        <mx:Script>
                <![CDATA[
                     import sample.FMSConnection;
                     import mx.controls.Alert;
                     import flash.net.NetConnection;
                     import flash.net.NetStream;
                     import flash.events.NetStatusEvent;




                        private var mic:Microphone;
                        private var fmsConnection:FMSConnection;
                        private var publishStream:NetStream;
                        private var recordedFileName:String;
                        private var recordedFileFullPath:String;

                        private function connect():void
                        {

                        NetConnection.defaultObjectEncoding = 
ObjectEncoding.AMF0
                        fmsConnection =new FMSConnection;
                        fmsConnection .objectEncoding=ObjectEncoding.AMF0;
 
fmsConnection.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler);
                        fmsConnection.connect("rtmp://localhost/vod");

                        }

                        private function 
netStatusHandler(event:NetStatusEvent):void
                        {
                        trace(event.info.code);

                        switch (event.info.code)
                        {
                case "NetConnection.Connect.Success" :
                Alert.show("Connected");

                                        break;
                                default:
                        Alert.show("checkings");

                                }
                                }
                                private function startRecord():void
                                {
                                        mic = Microphone.getMicrophone();
                        mic.rate=22;
                        mic.gain=100;
                        if(mic!=null)
                        {
                                mic.setUseEchoSuppression(true);
                                publishStream = new
NetStream(fmsConnection);

 
publishStream.addEventListener(NetStatusEvent.NET_STATUS,fmsConnection.handleConnectionStatusEvent);
                                        publishStream.attachAudio(mic);
                                        recordedFileName="File1";
                                        
recordedFileFullPath="rtmp://localhost/vod"
+       "/" + recordedFileName;
                                        
publishStream.publish(recordedFileFullPath,
"RECORD");
                                        //Alert.show("publish() By " +
recordedFileFullPath);


                        }
                                else
                                Alert.show("Microphone not attach or not
functioning");

                                }

private function playRecording():void
{
         publishStream=new NetStream(fmsConnection);
         recordedFileFullPath="rmtp://localhost/vod"+"mp3:YoungLions";

 
publishStream.addEventListener(NetStatusEvent.NET_STATUS,fmsConnection.handleConnectionStatusEvent);
         Alert.show(recordedFileFullPath);
         publishStream.play(recordedFileFullPath);
}




private function stopRecording():void
{
       Alert.show(String(publishStream.time));

        publishStream.close();
        Alert.show("Closed");

}
private function disconnect():void
{
        fmsConnection.close();
        Alert.show("Disconnected");
}
                ]]>
        </mx:Script>
        <mx:Button x="119" y="30" label="Record" id="record"
click="startRecord();"/>

        <mx:Button x="339" y="30" label="Stop" id="stop"
click="stopRecording();"/>
        <mx:Text x="255" y="98" text="Text" width="136" id="timetxt"/>
        <mx:Button x="82" y="169" label="Connect" click="connect();"/>
        <mx:Button x="348" y="169" label="Disconnect" click="disconnect();"/>
        <mx:Button x="210" y="226" label="Play" click="playRecording();"/>



</mx:Application>


i execute this program but it cannot record voice.
at the same time i give the mp3 file to play in flex.
but mp3 file also cannot play
pls help me

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to