Using Scripts as a Source
You can include script as a source by sending a type-data string pair to your Windows Media Encoder application when you broadcast the stream. Windows Media Player automatically processes predefined command types:
- Windows Media Player interprets the TEXT and CAPTION types as captioned text and displays the data string in the caption window. The TEXT and CAPTION script command parameters can be plain text, SAMI, or HTML-formatted text. For the captions to be visible, users must have the Captions option selected in their player.
- Windows Media Player interprets the URL type as a URL and opens it in the user's default Web browser. If the user is viewing the stream from a player embedded in a Web page, the URL replaces this page. To avoid this, you can display the URL in another frame or in a new instance of the browser.
The following examples show how to use a script as a source. For end-to-end code examples, see Complete Code Examples.
Visual Basic Example
' Declare objects and variables.
Dim Encoder as WMEncoder
Dim SrcGrpColl As IWMEncSourceGroupCollection
Dim SrcGrp As IWMEncSourceGroup
Dim SrcAud As IWMEncSource
Dim SrcVid As IWMEncVideoSource
' Retrieve a source group collection.
Set SrcGrpColl = Encoder.SourceGroupCollection
' Create a source group called SG_1.
Set SrcGrp = SrcGrpColl.Add("SG_1")
' Create a video, an audio, and a script source object.
Set SrcAud = SrcGrp.AddSource(WMENC_AUDIO)
Set SrcVid = SrcGrp.AddSource(WMENC_VIDEO)
Set SrcScript = SrcGrp.AddSource(WMENC_SCRIPT)
' Specify the audio and video streams.
SrcVid.SetInput "DEVICE://Default_Video_Device"
SrcAud.SetInput "DEVICE://Default_Audio_Device"
' Specify the script plug-in.
SrcScript.SetInput "UserScript://"
' Finish configuring the encoding session.
' For example, specify the profile.
' Initialize and start the encoding process.
Encoder.PrepareToEncode
Encoder.Start
' Broadcast a text string, which appears in the
' player's caption window.
Encoder.SendScript 0, "TEXT", "This is a test"
See Also