Read Digital Edition


ADS BY GOOGLE
Top Three Links You Must Click On


Using File Object for Video on Demand and MP3 Playback
One new feature of Flash Media Server 2 is the File Object feature

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.
It's easy to change your default applications folder. Open conf/fms.ini in a text editor and change the variable VHOST.APPSDIR.

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.
Both run using the same default server-side ActionScript file, main.asc.

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;
}

About 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.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

  Subscribe to our RSS feeds now and receive the next article instantly!
In It? Reprint It! Contact advertising(at)sys-con.com to order your reprints!
Subscribe to the World's Most Powerful Newsletters

ADS BY GOOGLE
We talk a lot about social media on Marketing Trenches. And for good reason – Social media seems to...
Intel has put out its promised beta SDK for Windows (C and C++) and Moblin (C) developers working on...
InformationWeek stumbled on a Microsoft patent application dating back to 2006 deceptively titled “M...
Berlin-based ThinPrint AG, the printer virtualization house, thinks it’s got a cloud solution for th...
But on the web, access to services is implicit in the fact that the business is offering the service...
Behaving like it’s got a future, Sun Monday put out what it calls a significant new version of Virtu...
IBM has acquired Guardium, a seven-year-old subsidiary of Israel’s Log-On Software transplanted to M...
Oracle has offered to cordon off MySQL inside a combined Oracle-Sun to get the European Commission t...
The second set of charges filed last week against Indian outsourcer Satyam Computer Services founder...
Gartner told Reuters that it overestimated how many PCs Acer shipped in the last seven quarters by a...
Office Web Apps, Microsoft’s answer to Google Apps, are supposed to be out sometime in June along wi...
Gartner thinks the server business has stopped sliding into the abyss. Third-quarter sales weren’t a...
Gartner is buying ~$40 million-a-year AMR Research Inc for close to $64 million in cash. AMD special...
Singed by user reaction to its plans to up the price of its support contracts, SAP Tuesday postponed...
Apparently Google Gears ain’t gonna stick around that long. Google Apps will eventually get their of...
Oracle seems to have divided the open source ranks over the MySQL delay it’s having closing its acqu...
We hear – well, you know how people talk – that Oracle has been quietly meeting with the European Co...
The Korean government is going to sink around $172 million into cloud computing next year under a st...
In response to Opera’s complaints Microsoft has reportedly modified the proposed ballot screen that’...
Microsoft has sold the Folio and NXT businesses it got when it bought Fast Search and Transfer, the ...