Home | | Internet & World Wide Web HOW TO PROGRAM | | Internet Programming | | Web Programming | Using the Windows Media Player ActiveX Control

Chapter: Internet & World Wide Web HOW TO PROGRAM - Multimedia: Audio, Video, Speech Synthesis and Recognition

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

Using the Windows Media Player ActiveX Control

ActiveX controls enhance the functionality of Web pages with interactivity.

Using the Windows Media Player ActiveX Control

 

ActiveX controls enhance the functionality of Web pages with interactivity. In this section, we embed the Windows Media Player ActiveX control in Web pages, so that we can access a wide range of media formats supported by the Windows Media Player. The Windows Media Player and other ActiveX controls are embedded into Web pages with the object element.

    <?xml version = "1.0"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

 <!-- Fig. 33.4: EmbeddedVideo.html -->

 <!-- Video via the embed Element -->

    <html xmlns = "http://www.w3.org/1999/xhtml">

    <head>

      <title>Video via the embed Element</title>

      </head>

      <body>

      <h1>Displaying a Video using the embed Element</h1>

<h2>Car Driving in Circles</h2>

<table>      

<tr><td><embed src = "car_hi.wmv"         loop = "false"

width = "240" height =  "176">

</embed></td>    

      </tr></table>

      <hr />

      This page plays the video once.<br />

      Use the controls on the embedded video player to play the

      video again.

      </body>

</html>

 

 

Fig. 33.4 Embedding video with the embed element

 

The XHTML document of Fig. 33.5 demonstrates how to use the object element to embed two Windows Media Player ActiveX controls in the Web page. One of the controls plays a video. The other control plays an audio clip.

 

    <?xml version = "1.0"?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<!--      Fig. 33.5: MediaPlayer.html   -->

<!--      Embedded Media Player Objects -->

      <html xmlns = "http://www.w3.org/1999/xhtml">

      <head><title>Embedded Media Player Objects</title>

<script type = "text/javascript">

<!--

var videoPlaying = true;

 

function toggleVideo( b )

{

videoPlaying = !videoPlaying;

b.value = videoPlaying ?

"Pause Video" : "Play Video";

videoPlaying ?

VideoPlayer.Play() : VideoPlayer.Pause();

}

        // -->

        </script>

        </head>

25

        <body>

        <h1>

        Audio and video through embedded Media Player objects

        </h1>

        <hr />

<table>

<tr><td valign            = "top" align = "center">

<object id = "VideoPlayer" width = "200" height = "225"

classid =       

"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">

<param name = "FileName" value =

"car_hi.wmv" />

<param name           = "AutoStart" value = "true" />

<param name           = "ShowControls" value = "false" />

<param name           = "Loop" value = "true" />

</object></td>          

<td valign = "bottom" align = "center">

<p>Use the controls below to control the audio clip.</p>

<object id = "AudioPlayer"

classid =       

"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95">

<param name           = "FileName" value =

"http://msdn.microsoft.com/downloads/sounds/carib.mid" />

<param name           = "AutoStart" value = "true" />

<param name           = "Loop" value = "true" />

</object></td></tr>

           

<tr><td valign            = "top" align = "center">

<input name = "video" type = "button" value =

"Pause Video" onclick = "toggleVideo( this )" />

</td></tr>       

            </table>

            </body>

            </html>

 


Fig. 33.5 Using the object element to embed the Windows Media Player ActiveX control in a Web page

 

 

When the body of this document loads, two instances of the Windows Media Player ActiveX control are created. The object element in lines 33–41 creates a Media Player object for the file car_hi.wmv (specified on line 37). Line 33 indicates the start of the embedded object definition. The id property specifies the scripting name of the element (i.e., VideoPlayer). The width and height properties specify the width and height in pixels that controls occupy in a Web page. On lines 34–35, property classid specifies the ActiveX control ID for the Windows Media Player. ActiveX controls have unique classids which identify them. A complete list of ActiveX controls available free for download is found at browserwatch.internet.com/activex/activex-big.html. Another site that provides information about ActiveX is www.active-x.com.

Lines 36–40 specify parameters that are passed to the control when it is created in the Web page. Each parameter is specified with a param element that has name and value properties. The FileName parameter specifies the file containing the media clip. The AutoStart parameter is a boolean value indicating whether or not the media clip plays when it is loaded. The ShowControls parameter is a boolean value indicating whether the Media Player controls should be displayed. The Loop parameter is a boolean value indicating whether the Media Player should play the media clip indefinitely.

 

The object element in lines 44–51 embeds another Media Player object in the Web page. This Media Player plays the MIDI file carib.mid (specified with the FileName parameter). A MIDI (Musical Instrument Digital Interface) file is a sound file that con-forms to the MIDI standard for digital music playback. The Media Player starts playing the clip when it is loaded (specified by the AutoStart parameter) and infinitely loops the audio clip (specified with the Loop parameter).

 

The script at lines 10–23 shows that the Media Player can be controlled from a script. Clicking Pause Video calls function toggleVideo (line 14). The button is defined in the XHTML form in lines 54–55. The onclick event sets the toggleVideo function as the event handler passes this as an argument for the function. This event changes the button text in lines 17–18. Lines 19–20 use the boolean variable videoPlaying to deter-mine whether to call VideoPlayer’s Play or Pause methods which play or pause the video clip, respectively.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.