FMS3 Series (1): The first FMS program, connected to the FMS server (Flash / Flex both implementations)

2010-09-21  来源:本站原创  分类:Flash  人气:214 

FMS is a very cattle X things, in the end a number of cattle X I do not want to say, interested friends can baidu an understanding that, if it is not hands-on, then you point the link below, my search for a point brief summary of information about.

You can click here to learn about the basics of FMS: understand some basic concepts of FMS

FMS is usually done, and the development of Flash, or Flex integration, especially in the video stream rather prominent in this regard, quite a few success stories, such as http://www.tudou.com, www.ku6.com, http: / / www.15dv.com and other video sites are linked with the FMS. I also because of operational requirements, taking advantage of spare time to learn this skill, want to write a blog for ways to consolidate and share learning, hope hobby or in development work in this field to drum up correcting exchanges. OK, this paper to connect the FMS server as writing topics, to see if we learn where FMS should proceed gradually to a higher level.

Adobe Flash and Flex products can be combined with FMS programming, this example is simple, to more than Minato words I intend to achieve through the Flash and Flex to introduce two how to achieve our first FMS procedures "to connect to the FMS server . "

Not forget to wear machete in the mountains cutting wood, then we certainly can not do without technology development done on the development environment, development tools, development of language selection and preparation. Our tools in this article is the Flash CS 4, Flex Builder 3 and the FMS 3.0, the development of the language used is ActionScript 3.0, here I do not want to waste time introducing the software to install, I believe you read this article would not exist for the installation of software What is so complicated, OK, to see how the following coding to achieve.

1, FMS should do

Used in this article to the FMS is very simple, mainly on the establishment of a FMS is the application of the method is very simple. Locate the directory you installed the FMS you will find inside a appliations directory. Correct, it is the management of FMS applications directory, enter the directory in which to establish a folder on OK, I created a folder for the "firstFMS".

Second, Flash to connect to the FMS server

First, a Flash file (ActionScript 3.0) and save it in a directory (to decide it), the. Then open the Components panel (you can press Ctrl + F7) from the component panel, drag a button component to the stage just to establish a good Flash (Flash is something that shows a place), and then through the property panel (can be Ctrl + F3) button will just drag out a name (Flash in the name of him as an example, the stage of each component is an instance of an object corresponding to), I get the btnConnFMS.

After the completion of the above two steps back to the stage, the stage of the mouse click a blank position, and then also open the properties panel, you will find the properties panel and now there is not the same as the previous, the publishing options found under "Class", where I fill in for "ConnFMS", that I will have to file through ConnFMS.as this class that the current Flash encoded.

Above commitments by ConnFMS.as to work for Flash encoding, that how to do this? An ActionScript class file, save the Flash files before saving in the same directory on OK, remember this class file must be "ConnFMS.as". Here is the complete code ConnFMS.as:

package
(
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.display.MovieClip;
import flash.net.Responder;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.events.AsyncErrorEvent;

public class ConnFMS extends MovieClip
(
private var nc: NetConnection;

public function ConnFMS ()
(
btnConnFMS.label = "connected to the FMS";
)

private function onClickHandler (evt: MouseEvent): void
(
trace ("Connecting to FMS server");
nc = new NetConnection ();
nc.connect ("rtmp: / / localhost / firstFMS");
nc.addEventListener (NetStatusEvent.NET_STATUS, onNetStatusHandler);
)

private function onNetStatusHandler (evt: NetStatusEvent): void
(
switch (evt.info.code)
(
case "NetConnection.Connect.Success":
trace ("successfully connected FMS server!");
break;
case "NetConnection.Connect.Rejected":
trace ("insufficient permission to access FMS server, the connection is denied!");
break;
case "NetConnection.Connect.InvalidApp":
trace ("the specified application name not found");
break;
case "NetConnection.Connect.Failed":
trace ("Connection failed!");
break;
case "NetConnection.Connect.AppShutDown":
trace ("server-side application has been shut down (due to excessive consumption of resources and other reasons) or the server has been shut down!");
break;
case "NetConnection.Connect.Closed":
trace ("with the FMS connection interrupted!");
break;
)
)
)
)

3, Flex to connect to the FMS server

First establish a good Flex project, create an MXML file by default, simplified to achieve here directly in the MXML file to implement connection FMS. Code and Flash to connect to the FMS little difference, mainly NetConnection class to complete the study, the following code defines:

/ / Flex and FMS to establish a connection object
private var netConn: NetConnection;
/ / FMS server address, use the rtmp protocol
private var rtmpUrl: String = "rtmp: / / localhost / firstFMS";

Flash Player NetConnection directed by persistent RTMP connection to connect to the server to achieve this step through the NetConnection class connect () method to complete. As follows:

/ / When the Flex application starts when the server on the establishment of a connection with the FMS,
internal function onInit (): void
(
netConn = new NetConnection ();
netConn.connect (rtmpUrl);
netConn.addEventListener (NetStatusEvent.NET_STATUS, onNetStatusHandler);
netConn.addEventListener (AsyncErrorEvent.ASYNC_ERROR, onAsyncErrorHandler);
)

connect () method to open the specified protocol address of the FMS rtmp connection to the server. Once the NetConnection object to call the method will capture the FMS returns a network connection state, through NetStatusEvent event listeners can be returned status value (see the article in detail before the Flash part), AsyncErrorEvent event for the asynchronous exception is raised (both native asynchronous code ) when scheduling. Various states on the NetConnection details, please see this article before the Flash Examples in detail.

As simple examples, here I am not going to say crap, here is connected to the FMS through the Flex achieve the complete code:

<? Xml version = "1.0" encoding = "utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<! [CDATA [
import mx.controls.Alert;
/ / Flex and FMS to establish a connection object
private var nc: NetConnection;
/ / FMS server address, use the rtmp protocol
private var rtmpUrl: String = "rtmp: / / localhost / firstFMS";

/ / When the Flex application starts when the server on the establishment of a connection with the FMS
internal function onClick (): void
(
nc = new NetConnection ();
nc.connect (rtmpUrl);
nc.addEventListener (NetStatusEvent.NET_STATUS, onNetStatusHandler);
nc.addEventListener (AsyncErrorEvent.ASYNC_ERROR, onAsyncErrorHandler);
)

private function onClickHandler (evt: MouseEvent): void
(
trace ("Connecting to FMS server");
nc = new NetConnection ();
nc.connect ("rtmp: / / localhost / firstFMS");
nc.client = this;
nc.addEventListener (NetStatusEvent.NET_STATUS, onNetStatusHandler);
nc.addEventListener (AsyncErrorEvent.ASYNC_ERROR, onAsyncErrorHandler);
)

private function onNetStatusHandler (evt: NetStatusEvent): void
(
switch (evt.info.code)
(
case "NetConnection.Connect.Success":
trace ("successfully connected FMS server!");
break;
case "NetConnection.Connect.Rejected":
trace ("insufficient permission to access FMS server, the connection is denied!");
break;
case "NetConnection.Connect.InvalidApp":
trace ("the specified application name not found");
break;
case "NetConnection.Connect.Failed":
trace ("Connection failed!");
break;
case "NetConnection.Connect.AppShutDown":
trace ("server-side application has been shut down (due to excessive consumption of resources and other reasons) or the server has been shut down!,");
break;
case "NetConnection.Connect.Closed":
trace ("with the FMS connection interrupted!");
break;
)
)

private function onAsyncErrorHandler (evt: AsyncErrorEvent): void
()
]]>
</ Mx: Script>
<mx:Button x="135" y="89" label="Button" click="onClick()" fontSize="12" fontWeight="normal"/>
</ Mx: Application>

IV Notes

FMS is usually when the novice in learning will be a problem, that is connected through the NetConnection FMS server when the connection status always returned "NetConnection.Connect.Rejected" This state results, and then then there will be a "NetConnection. Connect.Failed "state, is what causes so wrong?

The first error from this instance you can get is to visit the FMS server permissions problem, if FMS does not provide sufficient access rights, visit the FMS usually the client will receive such an abnormal state. The second error is how did it? This is access to cause another, when the client does not have enough permissions to access the primary FMS server will return "NetConnection.Connect.Rejected" status and automatically disconnect the connection to the server with the FMS, "NetConnection.Connect.Failed" state itself is connect to a server failure is due, but here because of the permissions issues raised.

A few days ago many of my friends asked me this question in, how to solve this problem? If you are a technical expert on who, if they catch you in front of you interested, you first do? See the official documentation provided? Example code? Or what? OK, that in order to solve this problem is simple FMS server installed in the directory after an "applications" directory, which has two FMS FMS server installed by default (live and vod), casually open a default install and then open the inside The "readme.txt" file will see the following words:

================================================== ==============
Deploying an unsigned vod service
================================================== ==============

1. Create a new folder in the (FMS-Install-Dir) / applications folder.

2. If you are replacing the default Adobe signed live service, back up
the following files:
* Main.far
* Application.xml
* AllowedHTMLDomains.txt
* AllowedSWFDomains.txt

3. Copy files from (FMS-Install-Dir) / samples / applications / vod to the directory you created in step 1.

Now you know how to solve the above problems yet? ? This main.far, Application.xml, allowedHTMLDomains.txt and allowedSWFDomains.txt four files to your server directory created to solve the FMS, and run the above example programs, and then by FMS management console view to detailed connection information.

I usually use the FMS installation directory fms_adminConsole.swf to view connection information, you can use FMSfms_adminConsole.htm view.

相关文章