September 21, 1998
Your Web page is now ready to receive events from the Windows Media Player plug-in. The code below uses the OnDSScriptCommandEvt function to capture two variables (via the scType and scParam parameters) from the Windows Media Player. The scType parameter is used to designate the type of script command. The scParam parameter is used to designate a parameter of that script command. For example, if you want to change the caption in a text box, you would set scType to "Textbox", and you would assign the text that will appear in the text box to scParam, as follows:
function OnDSScriptCommandEvt (scType, scParam){ window.status=(scType) + (scParam); if (scType == "Textbox") { document.myform.textbox1.VALUE= scParam} }
In this example, an if statement is used to detect if scType is equal to the word "Textbox". If this is true, the text area is changed to the value of scParam. Be sure not to try to rename the OnDSScriptCommandEvt function, because the embedded Windows Media Player will expect this function name. The scType and scParam parameters are required. Even if you only need scType, always include some text in scParam.
You can add as many if statements as you wish for each scType. For example, you can have one script event that changes the text box, another script event that changes a graphic on your Web page, and a third script event that changes the background color of the page:
function OnDSScriptCommandEvt (scType, scParam){ window.status=(scType) + (scParam); if (scType == "Textbox") { document.myform.textbox1.VALUE= scParam}; if (scType == "Graphic") { graphicdiv.src = scParam}; if (scType == "Background") { self.bgCOLOR= scParam}; }
The Windows Media Player ActiveX control used by Internet Explorer is already capable of receiving events in the stream, so it does not need to be enabled. You can give the same name to the ActiveX control and the plug-in without fear of confusion in the code -- the browser will always load only the one that it needs, based on the current browser.
The ActiveX control uses the ScriptCommand event to capture script events, as shown in the example below. (We've used JavaScript code. You can also use VBScript, but keep in mind that many browsers cannot read VBScript.) Be sure to separate this code from any other JavaScript on your pages by delimiting it within its own <SCRIPT> and </SCRIPT> tags.
<script LANGUAGE="JavaScript" FOR="MediaPlayer" EVENT="ScriptCommand(scType,scParam)"> <!-- if (navigator.appName == 'Microsoft Internet Explorer') { if (sctype == 'Textbox') { document.myform.textbox1.VALUE= (scParam) } } //--> </script>
The if statement checks to make sure that the browser is Internet Explorer. If true, another if statement checks the scType parameter setting. If it is equal to "Textbox", the text area is changed to scParam. Notice that this last section of code is the same as the code used in the OnDSScriptCommandEvt function for Netscape Navigator. As with OnDSScriptCommandEvt, you can add as many if statements as you want for each scType:
<script LANGUAGE="JavaScript" FOR="MediaPlayer" EVENT="ScriptCommand(scType,scParam)"> <!-- if (navigator.appName == 'Microsoft Internet Explorer') { if (sctype == 'Textbox') { document.myform.textbox1.VALUE= (scParam) } if (sctype == 'Graphic') { document.graphicdiv.SRC= (scPraram) } if (sctype == 'Background') {self.bgCOLOR=(scParam) } } //--> </script>
Back to the Advanced Scripting for Cross-Browser Functionality page