共用方式為


Handling Events in a Web Page Displayed by Firefox

[The feature associated with this page, Windows Media Player SDK, is a legacy feature. It has been superseded by MediaPlayer. MediaPlayer has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer instead of Windows Media Player SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

When you embed the Windows Media Player control in a webpage, you can write script that handles events. For a list of events raised by the Player control, see Player Object.

If the mime type associated with an embedded Player control is application/x-ms-wmp, you can write event handlers that have the following format:

<SCRIPT for="Player" language="jscript" event="EventName(Params)">
  ...
</SCRIPT>

where EventName is the name of a Windows Media Player event, and Params is a list of the event's parameters. For example, the following code has a handler for the PlayStateChange event.

<OBJECT id="Player" type="application/x-ms-wmp" width="300" height="200">
  <PARAM name="URL" value="c:\MediaFiles\Seattle.wmv"/>
</OBJECT>

<P id="p1">...</P>

<SCRIPT for="Player" event="PlayStateChange(NewState)">
  document.getElementById("p1").innerHTML = "Play state: " + NewState;
</SCRIPT>

If you have several instances of the Player control on a webpage and if you use the format shown in the preceding example, then each event handler is tied to a specific instance of the Player control. In the preceeding example, the event handler is called only when the play state changes for the control that has id="Player".

If the mime type associated with an embedded Player control is not application/x-ms-wmp, you can write event handlers that have the following format:

<SCRIPT language="jscript">
  function OnDSEventNameEvt(Params)
  {...}
</SCRIPT>

where EventName is the name of a Windows Media Player event, and Params is a list of the event's parameters. For example, the following code has a handler for the PlayStateChange event.

<OBJECT id="Player" type="application/asx" width="300" height="200">
  <PARAM name="URL" value="c:\MediaFiles\Test.asx"/>
</OBJECT>

<P id="p1">...</P>

<SCRIPT>
  function OnDSPlayStateChangeEvt(NewState)
  {
    p1.innerHTML = "Play state: " + NewState;
  }
</SCRIPT>

If you have several instances of the Player control on a webpage and if you use the format shown in the preceding example, then each event handler is tied to all instances of the Player control and the event handler is called when the play state changes for any Player control on the page.

Note

If the mime type is not application/x-ms-wmp, the DoubleClick event is sent as OnDSDblClickEvt (not OnDSDoubleClickEvt) for compatibility with version 6.4 of the Player control.

 

Using the Windows Media Player Control with Firefox