Export (0) Print
Expand All

© 1996 by Steven Holzner. All rights reserved.

The Multimedia Control

Buy this book

Multimedia is certainly a hot topic, because it lets us create an integrated environment of video, sound, still pictures, and text. VBScript gives us access to multimedia through custom controls such as the media control interface (MCI) multimedia control. Let's take advantage of this and create a new Web page, multimed.htm. As we've seen, the multimedia control consists of a set of buttons much like you would see on a CD player:


	--------------------------------------------------------------
         |      |      |      |      |      |      |   _  |   _  |  __  |
         | |/|  | |\|  |  |\  |  ||  |  /|| |  ||\ |  | | |  | | |  /\  |
         | |\|  | |/|  |  |/  |  ||  |  \|| |  ||/ |  |_| |  |_| |  ==  |
         |      |      |      |      |      |      |      |      |      |
          --------------------------------------------------------------

With these buttons, we can control the operation of multimedia devices. The different device types that the multimedia control can work with are shown in Table 6.2.

Table 6.2 MMControl device types.

Name Type of Device
Animation Plays animation
CDAudio Plays CD audio
AVIVideo Plays .AVI video files
Other Device is not defined
Overlay Plays analog video
Sequencer The musical instrument digital interface (MIDI)
VideoDisc Plays video discs
WaveAudio Plays .WAV sound files

Let's see how to use this control with CD audio. We begin by adding a new multimedia control to a Web page, multimed.htm, and giving that new control the ID MMControl1:

<HTML>
<HEAD>
<TITLE>Multimedia Control Page</TITLE>
</HEAD>
<BODY LANGUAGE = VBScript>
<CENTER>
<H1>Multimedia Control Page</H1>
</CENTER>
<!- MMControl>
<PRE>
MMControl:  <OBJECT CLASSID="clsid:C1A8AF25-1257-101B-8FB0-0020AF039CA3" <--
            HEIGHT=50 WIDTH=400 ID=MMControl1></OBJECT>
</PRE>
   .
   .
   .

As we did earlier, we add a button, MMButton, to start the multimedia control:

<HTML>
<HEAD>
<TITLE>Multimedia Control Page</TITLE>
</HEAD>
<BODY LANGUAGE = VBScript>
<CENTER>
<H1>Multimedia Control Page</H1>
</CENTER>
<!- MMControl>
<PRE>
MMControl:  <OBJECT CLASSID="clsid:C1A8AF25-1257-101B-8FB0-0020AF039CA3"
            HEIGHT=50 WIDTH=400 ID=MMControl1></OBJECT>
</PRE>
<CENTER>
<INPUT TYPE = BUTTON NAME = "MMButton" VALUE = "Activate MM Control"> <--
</CENTER>
<BR>
    .
    .
    .

When the user clicks this button, we set the multimedia control to play CD audio and start it as before in MMButton_OnClick:

Sub MMButton_OnClick
              MMControl1.DeviceType = "CDAudio"
              MMControl1.Command = "Open"
        End Sub

We can do more with the multimedia control by using its StatusUpdate event, which is called when it switches modes (e.g., from Stop to Play). The mode of the multimedia control is stored in its Mode property, and the available settings appear in Table 6.3.

Table 6.3 Multimedia modes.

Mode Value Means
524 Device not open
525 Device stop
526 Device play
527 Device record
528 Device seek
529 Device pause
530 Device ready

If we add a textbox to our Web page, we can indicate the status of the multimedia control: whether it is playing or paused, or whatever condition it is in. We add a rich text box, RichText1, for this purpose:

<HTML>
<HEAD>
<TITLE>Multimedia Control Page</TITLE>
</HEAD>
<BODY LANGUAGE = VBScript>
<CENTER>
<H1>Multimedia Control Page</H1>
</CENTER>
<!- MMControl>
<PRE>
MMControl:  <OBJECT CLASSID="clsid:C1A8AF25-1257-101B-8FB0-0020AF039CA3"
            HEIGHT=50 WIDTH=400 ID=MMControl1></OBJECT>
</PRE>
<CENTER>
<INPUT TYPE = BUTTON NAME = "MMButton" VALUE = "Activate MM Control">
</CENTER>
<BR>
<!- RichText>
<CENTER>
<OBJECT CLASSID="clsid:3b7c8860-d78f-101b-b9b5-04021c009402"   <--
             HEIGHT=40 WIDTH=300 ID=RichText1></OBJECT>
</CENTER>
    .
    .
    .

We will display the status of MMControl1 with the MMControl1_StatusUpdate() subroutine; the control calls this subroutine when its status changes:

Sub MMControl1_StatusUpdate()
             .
             .
             .
        End Sub

In this subroutine, we place the correct text into the rich text box to match the control's status:

Sub MMControl1_StatusUpdate()
  -->        If MMControl1.Mode = 525 Then RichText1.Text = "Stopped."
  -->        If MMControl1.Mode = 526 Then RichText1.Text = "Playing."
  -->        If MMControl1.Mode = 527 Then RichText1.Text = "Recording."
  -->        If MMControl1.Mode = 528 Then RichText1.Text = "Seeking."
  -->        If MMControl1.Mode = 529 Then RichText1.Text = "Paused."
  -->        If MMControl1.Mode = 530 Then RichText1.Text = "Ready."
        End Sub

And that's it—now our multimedia program is set. Run it as shown in Figure 6.8. If you place a music CD in your CD-ROM drive, you can use the multimedia control to control it and play music. (Even if you don't have a sound card, CD-ROM drives often have earphone jacks for this purpose.) In addition, the status of each multimedia device is shown. Our new Web page is a success. The multimed.htm file appears in Listing 6.4.

Figure 6.8 Our multimedia control plays CD music.

Listing 6.4 multimed.html

<HTML>
<HEAD>
<TITLE>Multimedia Control Page</TITLE>
</HEAD>
<BODY LANGUAGE = VBScript>
<CENTER>
<H1>Multimedia Control Page</H1>
</CENTER>
<!- MMControl>
<PRE>
MMControl:  <OBJECT CLASSID="clsid:C1A8AF25-1257-101B-8FB0-0020AF039CA3"
            HEIGHT=50 WIDTH=400 ID=MMControl1></OBJECT>
</PRE>
<CENTER>
<INPUT TYPE = BUTTON NAME = "MMButton" VALUE = "Activate MM Control">
</CENTER>
<BR>
<!- RichText>
<CENTER>
<OBJECT CLASSID="clsid:3b7c8860-d78f-101b-b9b5-04021c009402"
             HEIGHT=40 WIDTH=300 ID=RichText1></OBJECT>
</CENTER>
<SCRIPT LANGUAGE = VBScript>
        Sub MMButton_OnClick
              MMControl1.DeviceType = "CDAudio"
              MMControl1.Command = "Open"
        End Sub
        Sub MMControl1_StatusUpdate()
             If MMControl1.Mode = 525 Then RichText1.Text = "Stopped."
             If MMControl1.Mode = 526 Then RichText1.Text = "Playing."
             If MMControl1.Mode = 527 Then RichText1.Text = "Recording."
             If MMControl1.Mode = 528 Then RichText1.Text = "Seeking."
             If MMControl1.Mode = 529 Then RichText1.Text = "Paused."
             If MMControl1.Mode = 530 Then RichText1.Text = "Ready."
        End Sub
</SCRIPT>
</BODY>
</HTML>

That's it for our ActiveX control chapter. In this chapter, we've explored many controls: 3-D buttons, 3-D frames and panels, grid controls, graph controls, AVI file controls, multimedia controls, spin buttons, progress bars, and more. As you can see, there is a great deal of power here—all that remains is to put it to work.

© 1996 by Steven Holzner. All rights reserved
Show:
© 2015 Microsoft