![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Handling Multimedia Control Errors As mentioned earlier, using the Multimedia control has the potential for errors. A well-designed program must detect multimedia errors and handle them gracefully, reporting needed corrective action to the user when possible. Fortunately, the Multimedia control provides you with the necessary capabilities:
A Multimedia Control DemonstrationNow that we have explored the more important details of the Multimedia control, lets see just how easy it is to use. The project SOUND2 uses the Multimedia control to implement a simple media player. You can open a media file (MIDI, WAV, or AVI) or the CD Audio device (assuming an audio CD is in the drive). Then you can use the Multimedia controls buttons to play the device. Theres no error handling in the programa feature you might want to add. In fact, you could add any number of enhancements to the program. The Multimedia control has enough power to serve as the heart of a full-featured media player. A good project to tackle on your own would be modifying this program so that the Multimedia control is hidden, but still used as the programs interface to the MCI. The program, shown operating in Figure 16.3, has a single form with two controls: Multimedia and CommonDialog. Theres also a File menu with three commands: Open, Play CD, and Exit. The forms objects and properties are shown in Listing 16.3 and its code in Listing 16.4.
Listing 16.3 Objects and properties in SOUND2.FRM. Begin VB.Form Form1 Caption = Multimedia Player Begin MSComDlg.CommonDialog CommonDialog1 End Begin MCI.MMControl MMControl1 End Begin VB.Menu mnuFile Caption = &File Begin VB.Menu mnuFileOpen Caption = &Open End Begin VB.Menu mnuFilePlayCD Caption = &Play CD End Begin VB.Menu mnuSeparator Caption = - End Begin VB.Menu mnuFileExit Caption = E&xit End End End Listing 16.4 Code in SOUND2.FRM. Option Explicit Const mciPause = 529 Dim DeviceOpen As Boolean Private Sub Form_Load() Dim x As Integer, y As Integer Initialize flag. DeviceOpen = False Set form size and control position. x = Form1.Width - Form1.ScaleWidth y = Form1.Height - Form1.ScaleHeight Form1.Width = MMControl1.Width + x Form1.Height = MMControl1.Height + y MMControl1.Left = 0 MMControl1.Top = 0 CommonDialog1.Filter = Wave (*.WAV)|*.wav|MIDI (*.MID)|*.mid|Video (*.AVI)|*.avi End Sub Private Sub Form_Unload(Cancel As Integer) Close the device. MMControl1.Command = Close End Sub Private Sub MMControl1_Done(NotifyCode As Integer) Enable the File menu. mnuFile.Enabled = True End Sub Private Sub MMControl1_PlayClick(Cancel As Integer) Set Notify so the Done event will be triggered. MMControl1.Notify = True Disable the menu while play is in progress. mnuFile.Enabled = False End Sub Private Sub MMControl1_StopClick(Cancel As Integer) Enable the menu. mnuFile.Enabled = True End Sub Private Sub mnuFileExit_Click() End End Sub Private Sub mnuFileOpen_Click() If the device is open, close it. If DeviceOpen Then MMControl1.Command = Close DeviceOpen = False End If Show the Open dialog. CommonDialog1.ShowOpen If user cancels, exit sub. If CommonDialog1.FileName = Then Exit Sub Set MM control properties. MMControl1.FileName = CommonDialog1.FileName MMControl1.DeviceType = MMControl1.Command = Open DeviceOpen = True End Sub Private Sub mnyFilePlayCD_Click() Open the CD Audio device. The CD should already be inserted in the drive. MMControl1.DeviceType = CDAudio MMControl1.Command = Open DeviceOpen = True 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 |