Windows Media : Handling Events

Goal: To catch and handle events sent by the Windows Media Player in Internet Explorer. In addition to over 100 properties and more than 20 methods, the Windows Media Player also sends over 20 events. These events allow for a greater level of interactivity between the Media Player and the Web page that hosts it. By listening for and catching events such as the Buffering event, we can handle errors more gracefully and bring data to the user.

Code to Include
Since we're only dealing with event handling in the ActiveX model, we'll start with code that will instantiate the Media Player ActiveX control. We'll deal with the plug-in architecture in a subsequent section..

<object id="MediaPlayer1" width="160" height="182" classid="clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" standby="Loading Microsoft Windows Media Player components..." type="application/x-oleobject"> <param name="AutoStart" value="False"> <param name="FileName" value="http://webserver/path/your-file.asx"> <param name="ShowControls" value="True"> <param name="ShowStatusBar" value="False"></object> Next, we'll define a form and some text areas so that we can show what is happening with the client:
Now we'll define some event-handling routines. This first one, which handles the MarkerHit event, simply changes the "value" property of a text box to something that the user can understand. In this case, the MarkerHit event is sending a parameter that will specify the number of the current marker of the file. We're then using the GetMarkerName() method to return the name of the marker. SCRIPT FOR="MediaPlayer1" EVENT="MarkerHit(markerNum)" LANGUAGE="Jscript"&gt; myForm.text2.value = MediaPlayer1.GetMarkerName(markerNum) We'll handle the next event, Buffering, in a slightly different way. Since we cannot access the code in the The code above will call a function in the
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish