The Multimedia Control's Command Language

The Multimedia control supports its own miniature command language (although this language is not nearly as robust as the Visual Basic language). The Multimedia control accepts, in its Command property, one word commands that control whatever device is currently playing. Table 14.6 describes each of the commands and their meanings.

Table 14.6. These commands form the multimedia control's Command property language.

Command Description
Back Steps backward through the device's tracks.
Close Closes the device.
Eject Ejects the CD from the CD-ROM drive.
Next Goes to the beginning of the next track (or to the beginning of the final track if the last track is current).
Open Opens the device.
Pause Pauses the device.
Play Plays the device.
Prev Returns to the beginning of the current track. If used within three seconds of the most recent Prev command, Prev returns to the beginning of the previous track (or to the start of the first track if the first track is current).
Record Initializes recording on the device.
Save Saves the open device file.
Seek Seeks backward or forward a track (programmers typically use Next or Prev instead of Seek due to its directional ambiguity).
Stop Stops the device.
Step Steps forward through the device's tracks.

As your application runs, when your code changes the value in the Command property to a different property, the multimedia control responds accordingly.

tip

Your users do not have to control the multimedia control's device. You can hide all the control's buttons and, through the Command property, control the device with your application's code.

Putting Together a CD Player

Now that you've been introduced to the multimedia control, you can use it to put together an application very quickly. Start a new project and assign properties shown in Table 14.7 to the application.

Table 14.7. Use these properties and values on the multimedia control form.

Control Description
Form's Name frmCD
Form's Caption CD Player
Form's Height 3600
Form's Width 4800
Label #1's Name lblCD
Label #1's Alignment 2-Center
Label #1's BorderStyle 1-Fixed Single
Label #1's Caption CD Player
Label #1's Font style Bold
Label #1's Font size 18
Label #1's Height 495
Label #1's Left 1320
Label #1's Top 480
Label #1's Width 1935
Label #2's Name lblTrack
Label #2's Alignment 1-Right Justify
Label #2's Caption Track:
Label #2's Font style Bold
Label #2's Font size 12
Label #2's Height 255
Label #2's Left 1200
Label #2's Top 2280
Label #2's Width 1215
Label #3's Name lblTrackNum
Label #3's Caption (blank)
Label #3's Font style Bold
Label #3's Font size 12
Label #3's Height 375
Label #3's Left 2520
Label #3's Top 2280
Label #3's Width 615
Multimedia control Name mmcCD
Multimedia control DeviceType CDAudio

Once you've placed these controls, enter the code you see in Listing 14.3 to complete the CD player application.

Listing 14.3. This code handles the CD player.

    1: Private Sub Form_Load()
    2: ' Open the CD
    3: mmcCD.Command = "Open"
    4: End Sub
    5:
    6: Private Sub Form_Unload(Cancel As Integer)
    7: ' Clean up the multimedia control when done
    8: mmcCD.Command = "Close"
    9: End Sub
    10:
    11: Private Sub mmcCD_StatusUpdate()
    12: ' Update the track number in the label
    13: lblTrackNum.Caption = mmcCD.Track
    14: End Sub
    

The application opens the CD-playing multimedia control when the form first loads. Line 8 removes the CD player from memory right before the application ends (as with files, you should close any multimedia device you open). Line 13 updates the track number every time the CD's status changes. The value in the multimedia control's UpdateInterval property specifies the interval between updates of the status (the default is 1000).

Figure 14.10 shows the running CD player. The application is simple, but it works! You can hone the application so that the CD player has a way to exit the application through a File|Exit menu option. You can also add error-checking and notification, as described in the next section.

Figure 14.10

This CD player application takes very little effort and time to create.

note

Obviously, some buttons that are disabled, such as the Record button, are not needed at all in this application. You can hide these buttons if you want to clean up the multimedia control a bit.

note

You've not only mastered the multimedia control as a CD player, but you've almost mastered the control for all other multimedia devices as well! You'll see in subsequent sections that you'll deal with the multimedia control in almost the same way you did here, no matter which multimedia device you want the multimedia control to mimic.

Top Home