Windows Media Services SDK banner art
PreviousNext

Creating an On-Demand Multicast with the SDK

You can set up and start a multicast using the Windows Media Technologies SDK instead of the administrative application. This section outlines the steps you must follow to set up a basic multicast to distribute content on demand, using only the SDK. The following examples are written from the perspective of a user who does local administration.

The following steps are covered in this example:

Creating an Instance of the Station Control Object

To create an instance of the Windows Media Station control object, use the following straight HTML code, which must not be placed within a <SCRIPT> section.

<OBJECT ID="MCM" HEIGHT=1 WIDTH=1
    CLASSID="CLSID:B00464B3-67D4-11D0-A464-00C04FC29CFB">
</OBJECT>

Connecting to the Server

Open a connection to the server running Windows Media Services. In the following example, the new Windows Media Station control object is called MCM. It connects to a server running on the same computer where the script is being run. However, as long as the Windows Media Station control is installed locally, you can also connect to a remote computer that is running the server.

MCM.Connect "LocalHost"

Creating a Station

Create a station for the multicast by using the Open method. In the following example, the first parameter for the Open method specifies a station named My Station. The second parameter specifies that all administrative clients on the server running Windows Media Services must have full read, write, and delete permissions. The Open method returns a Channel object, which can be referred to by the variable MyStation.

Set MyStation = MCM.Channels.Open( "My Station", 7 )

Setting Station Properties

After the station is created, set the properties. Before you can multicast over the station, you must set the following properties. Many of the optional descriptive properties are set in the following example, but you can change that in the code if you do want to set them.

Note  When you set the MulticastAddress and Port properties, make sure that the values do not duplicate those of an existing station. It can be difficult to track down duplicate multicast servers.

MyStation.MulticastAddress = "238.8.217.46"
MyStation.Port = 13767

Specifying Delivery Options

Specify if the multicast is intended either for distribution to other servers, or for viewing in Windows Media Player, or for both. In the following example, the distribution mode is set to allow the multicast to be viewed in Windows Media Player:

MyStation.DeliveryMode = MCM_DM_SESSIONLESS_3PH

Creating a Station Format

The station must contain at least one station format to tell Windows Media Player installations how to render the content in the multicast. The station format is contained in a ChannelFormat object. In the following example, the Advanced Streaming Format (.asf) file used as the multicast source is also used to specify the station format:

MyStation.ChannelFormats.Add "C:\ASFRoot\welcome.asf", _
   MCM_ASF_CH_FORMAT_FILE

Creating an .nsc File

After you set up a station, export it into a Windows Media Station (.nsc) file that is posted in an accessible location on a network for easy access by a client. In the following example, the .nsc file is written into the home folder of a Web server on the local computer. The second parameter specifies that an old file with the same name can be replaced.

MyStation.WriteNSC "C:\inetpub\wwwroot\mynsc.nsc", "True"

Creating a Stream

Once the station is created, use the Open method to create a stream to play in it. In the following example, the new stream is given the name MyStream, with a unicast URL as its source. Specify the access rights that clients can have to the stream. The enumeration types for access right is defined as MCM_PA_READ, MCM_PA_WRITE, MCM_PA_DELETE, and MCM_PA_ALL.

Set MyStream = MCM.Streams.Open ("mms://MyServer/welcome.asf", "MyStream", MCM_PA_READ)

Activating the Stream

Once you have a valid station and stream, activate the stream to associate it with the station. A station can have only one active stream. If you have several streams, you can switch from one to another while the station multicasts. Clients listening to the station can receive content from the active stream, but cannot select which stream is active. That is up to you. In the following example, only one stream is set as the active stream.

MyStation.SetActiveStream MyStream

Starting the Multicast

Finally, start the stream. In the following example, the stream is started at the beginning by specifying an opening position of 0 (zero) milliseconds past the start of the file.

MyStream.Start 0

Playing the Multicast

Now the stream is being multicast. A client on a subnetwork that receives the multicast can connect to the stream and play it.

PreviousNext


© 1996-1999 Microsoft Corporation. All rights reserved.