Windows Media : Script Commands

Description: Goal- To create custom script command events, used to create a multimedia environment with dynamic captioning and images synchronized to an ASF stream.

ITPro Today

February 18, 2002

3 Min Read
ITPro Today logo

Description: Goal- To create custom script command events, used to create a multimedia environment with dynamic captioning and images synchronized to an ASF stream.

ASF's true power lies in its ability to send script commands timed within an ASF stream. These commands are not handled intrinsically by the Media Player, but are instead handled by the underlying JavaScript environment in both Netscape Navigator and Microsoft Internet Explorer. Utilizing these commands, it becomes very easy to create rich, dynamic multimedia.

Using script commands in an ASF stream, it becomes possible to command the browser to do just about anything that the browser supports. It becomes possible, for instance, for the Media Player control to interact with DHTML, Java applets, plug-ins, and more.

More Details

A script command is just like any other Media Player event, except that it allows you to send whatever kinds of data you want to the browser. The browser receives the ScriptCommand event, along with two parameters. The first parameter is used to determine the type of script command that is being sent. Then your JavaScript can perform whatever functionality you program in, using the script command's second parameter as data. For example, you might create a script command event called "swapImage." Through code handled by the ScriptCommand event, you could change the src attribute of an tag based on the data held in the script command's second parameter.

Code to Include

We'll start with our regular cross-browser code, adding the appObs proxy applet for Netscape Navigator:

Next, we'll add some areas in which we can perform Dynamic HTML (DHTML) operations. We'll use an  tag, that we'll use to swap images. We'll also use a set of tags that will combine a 

and a . This is necessary because of the differences between the DHTML models in Netscape Navigator and Internet Explorer. For aesthetic reasons, we'll add You'll notice that we're using both "#content" and ".content" CSS classes. This, again, has to do with syntax differences between Netscape Navigator and Internet Explorer. As before, we'll be using a function called by the onload event of the browser. Now it is time to actually write the JavaScript. Place the following code at the very top of your Since the Script Command event is embedded in the ASF file itself, we'll need a way to add the script commands inside the ASF file. We can do this using the ASF Indexer tool (one part of the Windows Media tools package). First, open up the ASF Indexer -- the default location of this tool is Start->Programs->NetShow Services->ASF Indexer. Once it is running, select File->Open. This will bring up a dialog box which will allow you to specify a piece of ASF content. Click the "Edit Script Commands" button. This will bring up the "Script Commands" dialog box. Click "New." Choose a time for your script command (in hours:minutes:seconds.tenths format). Next change the name of the script command to your own custom type, and change the parameter field to specify the type of data your command will send.Your ASF Indexer should look similar to the image below. Browser/Platform CompatibilityThis code will work with Internet Explorer 4+ and Netscape Navigator 4+ on the Win32 platform.

Complete Article

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like