Click to return to the Windows Media Technologies home page    
Web Workshop  |  Streaming & Interactive Media  |  Windows Media Technologies

Calling VBScript from Within Windows Media Services


Updated December 30, 1998

One of the most powerful features of Windows Media Technologies (WMT) is its ability to embed timed script events within the stream itself. By doing this, one can do anything that VBScript or JavaScript can do, from firing events within the browser, to calling events within other ActiveX™ controls.

Here are the steps to take advantage of the ability to send script events into the WMT stream:

Build ASF Content with Script Events

Embedding script events involves sending a time for the event to happen, an event name, and a parameter. The event name can be anything you want, as long as you have the VBScript or JavaScript code necessary to interpret it on the client. How you get the events and parameters into the stream depends on what tool you use to create your Windows Media Services content. Here's a quick rundown.

Company Name and Tool Name Description
Digital Renaissance
T.A.G. Editor Non-MSDN Online link
T.A.G. Editor provides detailed property sheets and timeline representation for simple and complex script commands to be embedded in the media file— ASF, audio ASF, or slide show ASF. There are four types of command types (TAG Types) and four ways that these commands are executed at a specific time in the stream). The T.A.G. Editor provides nearly 10 predefined commands and 4 types of custom commands.
Command Type Time in the Media Hot-spot click Graphic click Drop list
URL Flip yes yes yes yes
Pass URL to the Browser yes yes yes yes
Marker yes      
Custom Script yes yes yes yes

Each command type can be assigned an action on the media, such as pause, stop, play, or continue.
T.A.G. Editor will also automatically  embed the commands into the ASF stream, generate the VBScript or JavaScript to interpret the command, and create the HTML files to be run. No coding is required. The software will also generate a TXT file with all the script commands for reference and use with command-line utilities.
Microsoft Corporation
Windows Media Encoder
This is the best way to insert script events (for uses such as ad insertion) into a live stream. Open the Windows Media Encoder, follow the configuration wizard through to set up this encoding session, and send script events.
Microsoft Corporation
Microsoft Windows Media Services T.A.G. Author
Insert, Add Custom Script, and then fill in boxes for Time, Type (event), and Parameter. Separate multiple parameters with commas. Target URL flips into frames with event type (bstrtype) URL and parameter (bstrparam) equal to URL&&framename. Then build the ASF as usual and use HTML and VBScript or JavaScript to interpret the events.
Microsoft Corporation
WAVTOASF
Create a script file in Notepad or your favorite text editor. Compile your ASF with the - script scriptfile.txt switch added to the command-line prompt (where scriptfile.txt is the name of your script file). Target URL flips into frames with event type (bstrtype) URL and parameter (bstrparam) equal to URL&&framename. Sample MS-DOS command-prompt syntax: wavtoasf -in wavfile.wav -out newasf.asf -leadtime 5000 -script scriptfile.txt
Microsoft Corporation
VIDTOASF
Same as with WAVTOASF. Sample MS-DOS command prompt syntax: vidtoasf -in avifile.avi -audiofile wavfile.wav -out newasf.asf -leadtime 5000 -script scriptfile.txt
Sonic Foundry
Sound Forge Non-MSDN Online link
Pause the audio or video at the point you want the event to go. Go to Special, and then Drop Marker. Right-click on the marker icon, and select Edit. For the marker name, type ASF event:parameter (no spaces between event and parameter).

Create HTML Pages to Interpret Script Events

Now that you have created ASF files with script events in them, you will need to embed the Windows Media Player in the page using the <OBJECT> tag.

Next, you will need to add some script code to receive and interpret the events and parameters being sent from the Windows Media Services stream. Here's an example:

MediaPlayer refers to the Windows Media Player control. This segment of code should come after the <TITLE> tag in your HTML.

This subroutine says that if the Windows Media Player control sends an event (bstrtype) called variable, to plug the parameter it sends with it (bstrparam) into the subroutine and then act upon it. Remember that this won't work unless your ASF stream contains these events and parameters.

In this example we send script events in the stream that make a dialog box appear at specific times. Here is the VBScript used:

So, if the Windows Media Player control sends an event, and it matches the event in the subroutine, then the script inserts the parameter into the subroutine and carries out the function. In this case, if the event it sends is called Dialog, then it inserts the parameter sent with it into the MsgBox command.

In the preceding example, here are the events and parameters inserted into the stream.

Time Event Parameter
00:00:04.0 Dialog Thumbs Up!
00:00:11.0 Dialog Piggy Bank!
00:00:17.0 Dialog Point to the Left!
00:00:26.0 Dialog Show Me the Money!
00:00:31.0 Dialog OK, Show Me the Spare Change!
00:00:37.0 Dialog What a Hand!

Additional scripting information and code samples are available in the MSDN Online Samples area (see Windows Media Technologies in the Table of Contents).



Back to topBack to top

Did you find this material useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.