Windows Media Player SDK banner art
PreviousNext

Adding Button Click Events

This topic applies to Windows Media Player version 6.4 only.

The following SPAN tags position the images for the play, pause, and stop buttons.

<SPAN STYLE="position:absolute;
    left:0px;
    top:224px;
    width:94px;
    height:38px;"
    ONCLICK="MediaPlayer.Play()"
    >
    <IMG src="../art/sample2/play.gif"></span>

<SPAN STYLE="position:absolute;
    left:94px;
    top:224px;
    width:94px;
    height:38px;"
    ONCLICK="MediaPlayer.Stop();MediaPlayer.CurrentPosition=0;"
    >
    <IMG src="../art/sample2/stop.gif"></span>

<SPAN STYLE="position:absolute;
    left:188px;
    top:224px;
    width:94px;
    height:38px;"
    ONCLICK="onPause();"
    >
    <IMG src="../art/sample2/pause.gif">
</SPAN>

Much of the HTML in the above example is for positioning the buttons on the faceplate. However, note that each SPAN tag has an ONCLICK attribute that specifies a script command for the onClick event. This is the crucial link between dynamic HTML (DHTML) and the Windows Media Player object. When a user clicks on one of the spans containing a button graphic, it calls the specified script.

The scripts for the play and stop buttons are simple. The first calls the Play method, and the other sets the CurrentPosition property to zero.

The script for the pause button is somewhat more complicated, because the button has a more complex behavior. If clicking the button called the Pause method and did nothing else, the user would have to click the play button to restart playback. Typically a pause button will also restart playback from a paused state, so it's a good idea for a custom faceplate to act the same way. The following script function makes the pause button toggle between calling the Play method and calling the Pause method.

function onPause()
{
    if(MediaPlayer.PlayState==1)
        MediaPlayer.Play();
    else if(MediaPlayer.PlayState==2)
        MediaPlayer.Pause();
}

The value of the PlayState property reflects what Windows Media Player is doing at any time. If the value equals 1, Windows Media Player is in a paused state, and the above script responds by resuming playback. Otherwise, Windows Media Player was not paused, and the script calls the Pause method.

PreviousNext


© 2000-2001 Microsoft Corporation. All rights reserved.