| By Robert Sandie | Article Rating: |
|
| February 26, 2006 05:00 PM EST | Reads: |
18,999 |
Flash Media Server 2 offers a unique combination of traditional streaming media capabilities and a flexible development environment for creating and delivering media experiences to your audiences. These include traditional media like video on demand, live web-event broadcasts, and MP3 streaming, as well as rich media communication applications like video blogging, video messaging, and multimedia chat environments.
One new feature of Flash Media Server 2 is the File Object feature, which enables real-time read/write file access to a defined sandbox on your server, enabling content management systems and database applications without using Flash Remoting. This is a simple example that you can expand for use with File Object applications.
In this article, you will learn about a rather simple application that lets you display FLVs and MP3s on demand with predefined components you build using Flash Professional 8. This application automatically grabs FLVs and MP3s from a specific location on your server but is extensible for other uses. For example, to customize this application for a photo album using JPEGs, you would just redefine the filter so it calls JPEGs.
This application demonstrates new File Object properties on the server side and works in conjunction with the DataGrid, FLVPlayback, and MediaPlayback components on the client side. It demonstrates an alternative to XML-driven playback lists. If you wish to learn more about XML FLV lists, check out Lisa Larson's article, Creating a Dynamic Playlist for Streaming Video.
Setting Up Your Environment
To follow this code walkthrough, you will need on_demand_player.zip, the sample file download that accompanies this article. Here's what you should do with the contents of the ZIP archive:
- Place the FileObj and MyCollection folders in your Flash Media Server applications directory (by default, this is Flash Media Server 2\applications\).
- Put the OnDemandPlayer folder anywhere on your development machine.
- Place the MP3s and FLVs that you want to stream into the MyCollection/streams/_definst_/ folder.
Flash Media Server 2 has two applications that control the logic, FileObj and MyCollection. When OnDemandPlayer.swf is instantiated, it accesses FileObj, which returns the content into a DataGrid. When the user clicks an object in the DataGrid, it calls the video based in MyCollection.
Setting Up Flash Media Server
To make this application to work, you need to configure File Access and Stream Access.
File Access
The File Object class allows access to a sandbox within your server file system. To protect against any misuse, Flash Media Server allows access to files within a sandbox specified for the virtual host where the application instance is running. To define your server-side sandbox, go into your application.xml file in the FileObj folder. Define where you are storing the FLVs and MP3s that you wish the server to find:
<FileObject>
<VirtualDirectory>/approot; C:\Program Files\Macromedia\Flash Media Server
2\applications\MyCollection\streams\_definst_\
</VirtualDirectory>
</FileObject>
You have just enabled secure file access to this defined sandbox. You can set up multiple file object directories by consecutively adding virtual directories.
Stream Access
You will also need to set up your Vhost.xml, which you can find in your conf/_defaultRoot_/_defaultVhost_/ subfolder in the Flash Media Server 2 folder because you must tell the server when you call "/approot" from the Vhost instance that it should look in the specified directory. You will need to define where you streams are located (should be the same as the setting you defined earlier for FileObject):
<VirtualDirectory>
<Streams>/approot; C:\Program Files\Macromedia\Flash Media Server
2\applications\MyCollection\streams\_definst_\
</Streams>
</Virtual Directory>
Examining the Server-Side ActionScript
There are two applications running on the Flash Media Server:
- FileObj supports file access and filter functions pointing to your stream sandbox.
- MyCollection supports FLVPlayback component functions.
When you develop any Flash Media Server application, it is always easiest to start with the server-side ActionScript. Doing this allows you to debug and simulate the client-side actions using trace statements. This not only cuts down on your development time but prevents headaches later on.
You may notice that there are extra functions in main.asc in your FileObj folder. Notice there is more server-side ActionScript than is required for this application. This is what I use to handle all the file access commands in a familiar framework or API. I hope you will find this code useful and repurpose it for future file access functions.
Let's go over a few key functions in this file.
Constructor for File Class this.myFile = new File(name);
This construct command creates an instance of the file class as object myFile. The variable, name, can be either a file or directory. In this demonstration, you will be passing your alias directory into here to gather information about it (by default, approot).
File.List for File Class var dirList = this.myFile.list(filter);
This is the list function from which the DataGrid on the client side takes information. The list method returns an array with an element for each file in the directory. You can filter this further with the filter function:
function filter(name)
{
if ( name.lastIndexOf( ".flv") != -1 || name.lastIndexOf(".mp3") != -1){
return true;
}
return false;
}
Published February 26, 2006 Reads 18,999
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Robert Sandie
Robert Sandie interned at Macromedia as a product manager for the Flash Media Server team. He recently earned his degree in Computer Science and Business from Lehigh University in Bethlehem, Pennsylvania, where he also played football for the Mountain Hawks. Robert has a wealth of experiencing leading Flash projects and developing Flash video applications. To view his latest endeavors, catch up with him at robertsandie.com.

























