|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Playing MPG FilesThe Testing Department is calling again. Your new program, SuperDuperMultimedia4U, is terrificbut how about playing MPG format files? No problem, you say. You can play MPG format files with the multimedia control. How do you display the images in the MPG file? You connect the multimedia control to a picture box using the picture boxs hWnd property, placing that handle in the multimedia controls hWndDisplay property. Opening the file itself makes the buttons in the multimedia control active. Lets see an example; here, well play an MPG file named, say, demo.mpg. Add a multimedia control, MMControl1, to a program now, as well as a picture box, Picture1, in which well play demo.mpg. We also add a label, Label1, to display the multimedia controls status. When the form loads, we load the multimedia controls FileName property with the name of the file we want to open:
Private Sub Form_Load()
MMControl1.FileName = "c:\demo.mpg"
...
End Sub
Next we connect the picture boxs hWnd property to the multimedia controls hWndDisplay property to connect the picture box to the multimedia control:
Private Sub Form_Load()
MMControl1.FileName = "c:\demo.mpg"
MMControl1.hWndDisplay = Picture1.hWnd
...
End Sub
Finally, we open the file, which enables the buttons in the multimedia control:
Private Sub Form_Load()
MMControl1.FileName = "c:\demo.mpg"
MMControl1.hWndDisplay = Picture1.hWnd
MMControl1.Command = "Open"
End Sub
Now when users click the buttons in the multimedia control, they can play, stop, and restart the MPG file as they like. The animation appears in the picture box Picture1. Besides playing the MPG file, we can display what the multimedia control is doing (for example, playing, stopped, and so forth) in a label, Label1, by adding this code to the multimedia controls StatusUpdate event handler:
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
Finally, we stop and close the multimedia control when the form is unloaded:
Private Sub Form_Unload(Cancel As Integer)
MMControl1.Command = "Stop"
MMControl1.Command = "Close"
End Sub
Thats itmultimedia controls can play files in this format just as they can play AVI files; our MPG player is a success. The code for this example is located in the mpgplayer folder on this books accompanying CD-ROM. Keeping Track Of Multimedia Command Execution Using NotificationYou can gain more control over the multimedia control using the Notify property and the Done event. When you set a multimedia controls Notify property to True, youll get notification when the control finishes executing commands. How does it notify you? It generates a Done event. In fact, when you set Notify to True, your program is only supposed to be notified when the multimedia control is finished with the next command, but in fact, Done events appear to be generated for every command as long as Notify is True. Lets see an example. Here, we add a multimedia control, MMControl1, to a program and set its Notify property to True when the form loads: Private Sub Form_Load() MMControl1.FileName = "C:\WINDOWS\MEDIA\DING.WAV" MMControl1.Command = "Open" MMControl1.Notify = True End Sub When the control finishes executing a command, it fires a Done event, which we catch in an event handler procedure: Private Sub MMControl1_Done(NotifyCode As Integer) End Sub Here, the event handler procedure is passed a notification code, NotifyCode, which can take these values:
In this example, we just display a message box, indicating to the user that the multimedia command is finished:
Private Sub MMControl1_Done(NotifyCode As Integer)
MsgBox "Finished the multimedia command."
End Sub
Using multimedia notification, you can coordinate your multimedia actionsfor example, if you have two multimedia controls, you might not want to start playing sounds with one until the other is finished playing its own sounds.
|
|
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. |