|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Displaying The Multimedia Controls StatusThe Testing Department is calling again. Your multimedia program, SuperDuperSounds4U, is terrific, but how about a control panel that shows the current operationplay, stop, pause, and so on? Hmm, you think, how can you do that? You can use the Mode property to determine the current operation in a multimedia control. Here are the possible values for that property:
As you can see, the Mode property tells you whats going on with the multimedia controlbut when do you use the Mode property? You usually use that property in the multimedia controls StatusUpdate event handler. The StatusUpdate event occurs at regular intervals as specified in the UpdateInterval property (this property is set in milliseconds). You can take advantage of the StatusUpdate event to keep the user appraised of the status of multimedia operations. Lets see an example. Here, well display the status of a multimedia control, MMControl1, in a label control, Label1. We start with a Select Case statement in the StatusUpdate event handler, which uses the controls Mode property as the selection criterion:
Private Sub MMControl1_StatusUpdate()
Select Case MMControl1.Mode
...
End Select
End Sub
Now we check for the various possible multimedia operations by setting up case statements for possible values of the Mode property:
Private Sub MMControl1_StatusUpdate()
Select Case MMControl1.Mode
Case mciModeReady
Case mciModeStop
Case mciModeSeek
Case mciModePlay
Case mciModeRecord
Case mciModePause
End Select
End Sub
Next we set up a string, strMode, to hold the current multimedia mode, and display that mode in a label control in the program, Label1, this way:
Private Sub MMControl1_StatusUpdate()
Dim strMode As String
strMode = ""
Select Case MMControl1.Mode
Case mciModeReady
strMode = "Ready."
Case mciModeStop
strMode = "Stopped."
Case mciModeSeek
strMode = "Seeking."
Case mciModePlay
strMode = "Playing."
Case mciModeRecord
strMode = "Recording."
Case mciModePause
strMode = "Paused."
End Select
Label1.Caption = strMode
End Sub
Adding this code to a multimedia control program, such as the CD player program in Figure 22.2 (this program is developed later in this chapter), indicates to the user the current status of that control.
You can also display the time thats elapsed in the current operation. Lets see an example. Here, we set the time format in a multimedia control that opens the file C:\windows\media\canyon.mid (which comes with Windows) to mciFormatMilliseconds:
Private Sub Form_Load()
MMControl1.TimeFormat = mciFormatMilliseconds
MMControl1.FileName = "c:\windows\media\canyon.mid"
MMControl1.Command = "Open"
End Sub
Then we can report where we are in the MID file with the StatusUpdate event and the Position property, which holds the time thats elapsed from the beginning of the file, displaying that time in a label, Label1. Although weve set the time to milliseconds, its actually only reported in tenths of a second (probably because the computers Timer event can only occur 18.2 times a second), so we display the current time in the MID file this way:
Private Sub MMControl1_StatusUpdate()
Label1.Caption = Str(MMControl1.Position / 10)
End Sub
Closing The Multimedia ControlWhen youre finished with the multimedia control, you usually close it, typically in the Form_Unload event. Here, for example, we close the multimedia control when the form unloads using the Close command:
Private Sub Form_Unload (Cancel As Integer)
MMControl1.Command = "Close"
End Sub
In fact, its a good idea to execute a Stop command before closing the control, because closing the control does not necessarily stop operations like audio playback (for example, your CD will keep playing even if you exit your multimedia control CD player program, unless you explicitly stop the CD):
Private Sub Form_Unload (Cancel As Integer)
MMControl1.Command = "Stop"
MMControl1.Command = "Close"
End Sub
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |