Compartir a través de


Writing Event Code

[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.]

Events are treated similarly to attributes. You must give the event a value, and the value is the code you want to run when the event happens. The word "on" is added to the front of the event name; for example, the click event will become onclick.

The event value is in double quotes and starts with the word JScript followed by a colon. The code you want to run comes next, followed by a semicolon and the closing double quotes. For example, to stop playing when the user clicks on a button, type the following as an attribute in your BUTTON element code:

onclick = "JScript: player.Controls.Stop() ; "

If you have a code that requires quotes, use single quotes. Care must be taken when using quotation marks so that they are balanced properly. Here is an example of using both types:

onclick = "JScript: player.URL = 'https://proseware.com/laure.wma' ; "

You can also change attributes of your skin when handling an external event. For example, to close a view named myView, you could type:

onclick = "JScript: myView.close() ;"

Handling Events