Showcase and discover digital art at yex

Follow Design Stacks

Subscribe to our free newsletter to get all our latest tutorials and articles delivered directly to your inbox!

Examining the Client-Side Setup

Examining the Client-Side Setup

This client-side setup is rather simple because it is built with pre-existing components using basic OOP principles. The client-side framework consists of the following files located in the OnDemandPlayer folder:

  • OnDemandPlayer.fla
  • OnDemandPlayer.as

FLA Components

The FLA consists of three basic controls:

  • FLVPlayback: Used for streaming FLVs (new in Flash Professional 8)
  • MediaPlayback: The MP3 controller
  • DataGrid: Used for connecting FLVs and MP3s with the underlying architecture
  • OnDemandPlayer: A movie clip brought in pointing to ActionScript on the first frame (check the Library)

Connecting these client-side components is rather simple. Let’s go over a few key points.

ActionScript 2.0 and MovieClip Classes

A common best practice using OOP principles for scalable applications involves attaching movie clips as classes (see Figure 2). This is an excellent method for organizing and attaching ActionScript classes to the Stage. So if you are wondering how OnDemandPlayer.as is attached to OnDemandPlayer.fla, check out the Library.

Linking ActionScript to a movie

Figure 2. Linking ActionScript to a movie

This is comparable to using an #include file but is more manageable by simply attaching a movie clip from the Library:

attachMovie("OnDemandPlayer","mc",0); 

Connecting with the Server

The file access handshake with the server is set up through a basic makeConnection function:

public function makeConnection():Void {
nc = new NetConnection();
nc.connect("rtmp://"+serverName+"/"+appName);
nc.owner = this;
nc.onStatus = function(info) {
if (info.code == "NetConnection.Connect.Success") {
owner.dir();
}
};
}

Publishing Your Folder Directory

This connects to and sends Flash Media Server the folder name from which you wish to obtain your FLVs and MP3s:

nc.call("createFileObj", null, foldername); 

Getting the Stream Length

This connects with Flash Media Server to obtain the length for the FLV and MP3 lengths:

var streamlength = owner.nc.call("getStreamLength", null, stream_name); 

The FLVPlayback component has stream lengths built in. To set the MP3 length in MediaPlayback and display the length in the DataGrid, it must grab the information from the FileObj main.asc file.

Obtaining the List of File Objects

On the client side, you must gather the stream names as well as other information regarding File Object in an array. This is done with the dirResult function:

private function dirResult(folderName, owner):Void {
this.onResult = function(retVal) {
for (var i = 0; i<retVal.length; i++) {
var flv_name =
(retVal[i].name).substr((retVal[i].name).lastIndexOf("/")+1);
var index = flv_name.lastIndexOf(".");
var stream_name = flv_name.substring(index + 1, flv_name.length) + ":"
+ owner.folderName + "/" + flv_name.substring(0, index);
var streamlength = owner.nc.call("getStreamLength", null, stream_name);
owner.myDP_array.addItem({Name:flv_name, Length:retVal[i].streamlength,
CreationTime:retVal[i].creationTime, LastModified:retVal[i].lastModified,
Size:retVal[i].length});
}
};

Notice that the object retVal contains more than simply the stream name. It contains also creationTime, lastModified, and length (size of file).

These are just a few of the details you can gather using the List command on the server side.

Where to Go from Here

Using the file access and File Object features in Flash Media Server is an easy way to display content as an alternative to XML-driven data lists. The example shown in this article is a simple use case for just showing whatever media assets you have on your server. For other applications, you may want to consider combining the extensibility and organization of XML and ease of use with File Access as the perfect method for Flash Media Server on-demand applications. With this application you can easily drop your entire Flash video and MP3 media collection onto your server to stream your collection.

 This is the premier list for Flash Media Server developers and always contains informative development discussions. As a developer, I rely on this valuable resource whenever I face a tough problem. Just be careful what you ask, however, because if the answer is a simple Google’s search away, they will hound you for it.

I hope this has helped you understand the new file access feature built into Flash Media Server. I wish you the best of luck with your future Flash Media Server adventures.

Comments