Contents Index Topic Contents | |
Previous Topic: Accessing Properties Next Topic: Plug-in Samples |
Handling Events
Netscape Navigator employs a different event handling mechanism from Microsoft® Internet Explorer. While Internet Explorer communicates with the Microsoft® Windows Media™ Player control directly to handle events dispatched to and from the control, Netscape Navigator requires a proxy applet to send events to and from the plug-in. Additional coding is therefore required to load the applet into an HTML page, using the APPLET tag. The required proxy applet for the Windows Media Player plug-in is packaged in the Npds.zip file that contains the npDSEvtObsProxy class. You can download the applet class as follows:
<APPLET MYSCRIPT code=NPDS.npDSEvtObsProxy.Class width=5 height=5 name=appObs> </APPLET>An instance of the applet class must be created immediately after the HTML page is loaded. After the applet is loaded in the HTML page, you must register the events you require before they can be dispatched to the associated event handlers. In the examples that follow, appObs refers to this proxy applet object.
To use events in Netscape Navigator with the Windows Media Player control, you must do the following:
Register the Events
Before an event occurs, an event observer must be enabled to trap the event. The following code segment illustrates how to enable event observers.
var plugin = MediaPlayer; appObs.setByProxyDSScriptCommandObserver(plugin, true); appObs.setByProxyDSPlayStateChangeObserver(plugin, true); appObs.setByProxyDSReadyStateChangeObserver(plugin, true);This code registers three Windows Media Player control events: ScriptCommand, PlayStateChange, and ReadyStateChange. Each has its own observer. You must have event observers registered in a call to RegisterEventObservers when the page is loaded. To accomplish this, assign RegisterEventObservers() to the ONLOAD attribute of the BODY tag:
<BODY ONLOAD="RegisterEventObservers()">Then implement the RegisterEventObservers function in the script as follows:
function RegisterEventObservers () { // This helper function is required to register event observers with // the Java proxy. Registration MUST be done before desired events // will be sent. var plugin = document.MediaPlayer; // Here are the event observers we want activated in the plug-in. appObs.setByProxyDSScriptCommandObserver(plugin, true); appObs.setByProxyDSPlayStateChangeObserver(plugin, true); appObs.setByProxyDSReadyStateChangeObserver(plugin, true); // You can activate other event observers in a similar fashion. }This code ensures that all event observers are initialized before the Windows Media Player is started. It also prevents the user from having to take action to enable an event.
Add Event Handlers
Each registered event observer requires a corresponding event handler. For information about other events and their associated parameters, see Events.
In Microsoft® JScript® for Netscape Navigator, use the following syntax to declare an event handler, where EventName is the name of the Windows Media Player event:
function OnDSEventNameEvt (parameter1 [, parameter2... ] ) { // code goes here... }For the three events registered above, you would declare the event handlers as follows:
function OnDSScriptCommandEvt (scType, scParam) { // code goes here... } function OnDSPlayStateChangeEvt (OldPlayState, NewPlayState) { // code goes here... } function OnDSReadyStateChangeEvt (ReadyState) { // code goes from here... }
Top of Page
© 1999 Microsoft and/or its suppliers. All rights reserved. Terms of Use.