Skip to main content
Participant
August 21, 2010
Question

How to use FMS?

  • August 21, 2010
  • 1 reply
  • 1484 views

Hello,

  I had installed FMS3.5 on my system. BUt I Want to execute C:\Program Files\Adobe\Flash Media Server 3.5\samples\fms2_sample_apps

Inside it there is two folders applications and samles.My Samples folder there is different sample folders available like tuturial_text,tutorial_hello etc.

and inside that there is fla,swf and html files are present.

Also please tell me what is use of  *.asc file?

Please guide me.

Thanks.

    This topic has been closed for replies.

    1 reply

    Adobe Employee
    August 23, 2010

    Hi Sachin,

    Suppose FMS 3.5 is installed in your default location so you can see a sample application like  "Flash Media Server 3.5\documentation\samples\HelloWorld".

    Here you have following files :

    1. HelloWorld.asc - server application
    2. HelloWorld.as - client application

    3. HelloWorld.fla - client application

    So basically you have server application which sits in the application folder of FMS which is located @ <FMS root Dir>\applications. So you need to create application folder named "HelloWorld" inside applications folder and inside that you need to place the HelloWorld.asc file you can rename it to main.asc also as it accepts both. So using your client application HelloWorld.fla whenever you make NetConnection to this "HelloWorld" application you will do something like nc.connect("rtmp://localhost/HelloWorld") so it will execute either HelloWorld.asc or main.asc in your "HelloWorld" folder placed in applications folder whichever is present.

    When you run HelloWorld.fla in Flash Authoring tool like Flash CS5 by hitting ctrl+enter you will get swf file which you can later use directly without opening Flash CS5(it is just for editing your source files).

    In Flash Authoring tool you can publish the fla file to generate html also which has swf file embedded it by changing publish settings. So thats why you see swf, html and fla files at one place as it has been published to generate those.

    Regards,

    Amit

    Participant
    August 23, 2010

    Thanks amit for your answer.

    I had started FMS administration consol but don't know hpw to give nc.connect("rtmp://localhost/HelloWorld") in HelloWorld.fla file I don't have flash and I want to execute this application in flex i.e .mxml how i can do it.

    I had develop video sharing application in that i am getting Access of undefined property of fmeserver,FullscreenHnadler,phpserver,playbackstatus,uploadedfile,submitapixml,loadFMESAPIConfig() error occurs.

    I had created videshare folder and placed it in C:\Program Files\Adobe\Flash Media Server 3.5\applications  and created temporary folder inside c:\videoshare sample.flv file also created using flash media encoder server.

    Please help me how to igore these errors.

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
    <mx:Script>
        <![CDATA[
            // Event handler for the browse button
            var fileRef = new FileReference();
            // Select a video thumbnail
    public function onThumbClicked(event:Event):void {
       var thumb:ThumbnailViewer = event.target as ThumbnailViewer;
       mainVideo.source = "rtmp://" + videoshare + "/mytube/"+thumb.moviesource.name.split("/streams/_defInst_/")[1].split(".flv")[0];
       controls.label = "Stop";
       playbackstatus = "play";
       mainVideo.play();
    }
    private function onBrowse() : void {

       
        fileRef.addEventListener(Event.SELECT, selectHandler);

        try
        {
            var success:Boolean = fileRef.browse();
        }
        catch (error:Error)
        {
            trace("Unable to browse for files.");
        }
        function selectHandler(event:Event):void
        {
            videofile.text = fileRef.name;
            status.text = "Ready for upload";
            uploadedFile = fileRef.name;
            upload_btn.enabled = true;
        }
    }

    // Event handler for the upload button
    // Triggers an upload to the server

    private function onUpload():void {
       progressbar.label == "";
       var request:URLRequest = new URLRequest("http://" + localhost + "/videoscript/upload.php")

      // Add an event listener to monitor the progress of the upload
      fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);

    try
        {
          fileRef.upload(request);
          status.text = "Uploading " + fileRef.name + " ... ";
          browse_btn.enabled = false;
          upload_btn.enabled = false;
        }

        catch (error:Error) {
           status.text = "Upload error";
        }
    }
    // Displays the current progress of the upload
    private function progressHandler(event:ProgressEvent):void {
      progressbar.setProgress(Math.floor(event.bytesLoaded/1024),Math.floor(event.bytesTotal/1024));
         progressbar.label = "Uploading .. " + Math.floor(event.bytesLoaded/1024) + " of " + Math.floor(event.bytesTotal/1024) + " kbytes";'';
        
    }
    // Initializes the interface and connects to the Flash Media Server
    private var fmesport:String="1547";
        import flash.display.MovieClip;
        import flash.net.NetConnection;
        import flash.events.NetStatusEvent; 
        import flash.net.NetStream;
        import flash.media.Video;
        import flash.media.Camera;
        import flash.media.Microphone;
    public var activecommand:String = command;
    private function init() : void {

        var nc = new NetConnection();
        fmsserver = "sachinptdr";
        phpserver = "videoshare";
        fmesserver = "myserver.com";
      
        nc.connect("rtmp://"+ fmsserver +"/videoshare/");
       
        nc.addEventListener(NetStatusEvent.NET_STATUS,onConnect);
        playbackstatus = "stop";

        // Loads the FMES XML command files
        loadFMESAPIConfig();
       
        progressbar.mode = "manual";
        progressbar.label = "";

        // Event listener for the fullscreen mode
        Application.application.stage.addEventListener(FullScreenEvent.FULL_SCREEN, fullScreenHandler);
    }

    // Once the upload is complete, initialize the video conversion
    var fmessocket = new Socket();
        private function completeHandler(event:Event):void {
        status.text = "Upload complete";
       
        configureListeners(fmessocket);
        sendFMESCommand("submitjob");
        }

        // Establishes a new connection and connects to FMES
        private function sendFMESCommand(command:String) : void {
          
           if (fmessocket.connected) fmessocket.close();
           if (fmesserver && fmesport) {
                  fmessocket.connect(fmesserver, 1547);
              }
        }

        // Configures all listeners for the socket connection primarily for debug reasons
           private function configureListeners(dispatcher:IEventDispatcher):void {
               dispatcher.addEventListener( ProgressEvent.SOCKET_DATA, dataHandler );
               dispatcher.addEventListener( IOErrorEvent.IO_ERROR, ioErrorHandler );
               dispatcher.addEventListener( Event.CONNECT, connectHandler );
               dispatcher.addEventListener( Event.CLOSE, closeHandler );
               dispatcher.addEventListener( SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler );
           }

        // Triggered once connection closes
           private function closeHandler(event:Event):void {
               debug("closeHandler: " + event);
            }
        // Triggered once connection is established. This event should happen at the beginning of the encode       
        // Replaces the filename property of the XML command template with the uploaded file name value
           private function connectHandler(event:Event):void {
              
               if (activecommand == "submitjob") {
                   var replaceFileNameExp:RegExp = /1234/;
                   submitFMESCommand(submitapixml.replace(replaceFileNameExp,uploadedFile));
               }
           }

    // Submits a FMES command to the server through the established socket connect
    private function submitFMESCommand(commandxml:String) : void {
           debug(commandxml);
           var msg:String = commandxml;
           var bytes:ByteArray = new ByteArray();
           bytes.writeMultiByte( msg, "iso-8859-1" );
           var messageBytes:ByteArray = new ByteArray();
           var messageString:String = "CarbonAPIXML1 " + bytes.length.toString() + " " + msg;
           messageBytes.writeMultiByte( messageString, "iso-8859-1" );
           fmessocket.writeBytes( messageBytes );
           fmessocket.flush();
        }

    // Handles the response from FMES
       var fmesresponse = new XML( string );
       var activejobguid = (fmesresponse.attributes()[0].toString());
    private function dataHandler(event:ProgressEvent):void {
       var bytesAvailable:int = fmessocket.bytesAvailable;
       
        var type:String = fmessocket.readMultiByte( 13, "utf-8" );
        fmessocket.readMultiByte( 1, "utf-8" );
        var ttlBytes:int = int( fmessocket.readMultiByte( 2, "utf-8" ) );
        fmessocket.readMultiByte( 1, "utf-8" );
        var str:String = fmessocket.readUTFBytes( fmessocket.bytesAvailable );
        // Parses and assigns the response to a XML variable

        // Data can be received following the start job or the monitoring command
           switch (activecommand) {
           case "submitjob" :
       
        // Reads and stores the active job id
           
             var replaceGuidExp:RegExp = /1234/;
             var checkstatusxml = checkstatusapixml.replace("1234",activejobguid);
             activecommand = "checkjobstatus";
        // Checks for the job status after 2 seconds
             setTimeout(checkEncodingStatus,2000);
             break;
           case "checkjobstatus" :
        // Reads the received status variable from the XML response
             var currentstatus:String = fmesresponse.children()[0].children()[0].attribute("Status");
        // Reads the received progress from the XML response
             var encodingprogress:String = fmesresponse.children()[0].children()[0].attribute("Progress.DWD");
        // Updates the progress bar component
             progressbar.setProgress(Number(encodingprogress),100);
        // Updates the label for the progress bar depending on the current status
             if (currentstatus!="STARTED" && currentstatus!="COMPLETED") {
             progressbar.label = "Waiting in encoding queue";
             }
      
              if (encodingprogress=="0") {
                 progressbar.label = "Preparing encoding..";
              }
      
              else {
                 progressbar.label = "Encoding .. " +encodingprogress+ "% completed";
              }

       // Once encoding is complete, updates the UI and closes the socket connection to FMES
      
             if (currentstatus=="COMPLETED") {
                fmessocket.close();
                progressbar.label = "Encoding complete";
               
               
                browse_btn.enabled = true;
                upload_btn.enabled = false;
           }

    // If encoding is not complete, check again in 2 secs what the current status is
        else {
            setTimeout(checkEncodingStatus,2000);
    }
        break;     
    }
          
    }

    // Triggers the FMES command
           private function checkEncodingStatus() : void {
           submitFMESCommand(checkstatusxml);     
    }

    // Error handler
          private function ioErrorHandler(event:IOErrorEvent):void {
          debug("ioErrorHandler: " + event);
          }

    // Security handler
         private function securityErrorHandler(event:SecurityErrorEvent):void {
              debug("securityErrorHandler: " + event);         
              for (var foo:String in event) {     
                 debug(foo + " " + event[foo]);
              }
         }
        
        ]]>
    </mx:Script>

    <mx:HBox id="mainui" height="330" autoLayout="false">

        <mx:Panel width="380" height="306" layout="absolute"  scroll="false" id="panel1">
            <mx:VideoDisplay id="mainVideo" x="0" y="0" width="360" height="240"/>
            <mx:Button label="Play" id="controls" click="PlayPause()" y="242" x="3"/>
            <mx:Button label="Zoom" id="controls0" click="zoom()" y="242" x="299"/>
        </mx:Panel>

        <mx:Form id="uploadform" horizontalScrollPolicy="off" verticalScrollPolicy="off">
            <mx:FormItem label="Choose your file:" id="formitem">
               <mx:TextInput id="videofile" editable="false" x="10" y="358"/>
            </mx:FormItem>
            <mx:FormItem id="browsearea" >
               <mx:Button label="Browse" click="onBrowse()" x="180" y="359" id="browse_btn"/>
               <mx:Button label="refresh Videos" click="refreshVideos" x="436" y="10" enabled="true"/>
               <mx:Button id="upload_btn" label="Upload" click="onUpload()" width="68" enabled="false" x="256" y="360"/>
            </mx:FormItem>
              
        <mx:Text id="status"/>
            <mx:ProgressBar id="progressbar" width="277" enabled="true" indeterminate="false"/>
        </mx:Form>
    </mx:HBox>
    <mx:Tile autoLayout="true" id="videolist">
        <mx:Repeater id="rp1" dataProvider="{movieThumbnailList}">
            <local:ThumbnailViewer connection="{nc}" moviesource="{rp1.currentItem}" thumbClicked="onThumbClicked(event)" id="thumbnailviewer1"/>
        </mx:Repeater>
    </mx:Tile>

    </mx:Application>

    Adobe Employee
    August 23, 2010

    Your code has many errors like variables are not declared properly taking their scope into consideration like see below piece of code you will know the problem:

    // Initializes the interface and connects to the Flash Media Server

    private var fmesport:String="1547";

    import flash.display.MovieClip;

    import flash.net.NetConnection;

    import flash.events.NetStatusEvent;

    import flash.net.NetStream;

    import flash.media.Video;

    import flash.media.Camera;

    import flash.media.Microphone;

    public var activecommand:String = command;

    var fmesserver:String;

    var fmsserver:String;

    var phpserver:String;

    var checkstatusxml:String;

    private function init() : void {

         var nc = new NetConnection();

        fmsserver = "sachinptdr";

         phpserver = "videoshare";

         fmesserver = "myserver.com";

         

         nc.connect("rtmp://"+ fmsserver +"/videoshare/");

    So it is not FMS issue it is your code problem and also I can see nc.connect in your code which connects to videoshare application. So please correct errors and then try definitely it will work.

    Regards,

    Amit