Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Let’s see an example. Here, we set the Notify property of a multimedia control, MMControl1, to True, then open a WAV file:

Private Sub Form_Load()
    MMControl1.Notify = True
    MMControl1.FileName = "C:\WINDOWS\MEDIA\DING.WAV"
    MMControl1.Command = "Open"
...
End Sub

Then we add code to the Done event to display the error message for the current error, if there is one, using the Error and ErrorMessage properties:

Private Sub MMControl1_Done(NotifyCode As Integer)
    If MMControl1.Error <> 0 Then
        MsgBox MMControl1.ErrorMessage
    End If
End Sub

Now, if we execute an illegal command, we’ll be notified of the fact. For example, we might try to eject the WAV file, which is an illegal multimedia operation:

Private Sub Form_Load()
    MMControl1.Notify = True
    MMControl1.FileName = "C:\WINDOWS\MEDIA\DING.WAV"
    MMControl1.Command = "Open"
    MMControl1.Command = "Eject"
End Sub

In this case, we get the error message you see in Figure 22.7.


Figure 22.7  A multimedia control error message.

Stepping A Multimedia Control Forward Or Backward Frame By Frame

The Testing Department is calling again. Your program that plays the inspirational speech by the company’s founder is a big hit—but can’t you let the user move through it frame by frame for more impact? Hmm, you think, how do you do that?

You can use the Step and Back multimedia control commands to step through animations frame by frame. Each time you use these commands, you move forward or back by the number of frames set in the Frames property (the default is 1). To check if a multimedia control is connected to a device that can step this way, check the CanStep property—if it’s set to True, you can use the Step and Back commands.

Let’s see an example. We might connect a multimedia control, MMControl1, to a picture box, Picture1 this way so that it plays the file C:\windows\help\scroll.avi (which comes with Windows):

Private Sub Form_Load()
    MMControl1.FileName = "C:\windows\help\scroll.avi"
    MMControl1.hWndDisplay = Picture1.hWnd
    MMControl1.Command = "Open"
End Sub

Now when the user clicks a command button, Command1, we will advance MMControl1 by, say, five frames (after checking to make sure it can step):

Private Sub Command1_Click()
    If MMControl1.CanStep Then
        MMControl1.Frames = 5
        MMControl1.Command = "Step"
    End If
End Sub

When the user clicks another button, Command2, we can step back five frames:

Private Sub Command2_Click()
    If MMControl1.CanStep Then
        MMControl1.Frames = 5
        MMControl1.Command = "Back"
    End If
End Sub

That’s it—now the user can step forwards and backwards in the animation.

Starting From And To In A Multimedia Control

The Testing Department is calling again. The sound file you play in the opening screen of your new program, SuperDuperMultimedia4U, is 10 minutes long. Yes, you say, but it’s a good one. Can’t you play just part of it? they ask.

You can specify the start and end point of play and record multimedia operations with the From and To properties. You set these properties in the same time format you’ve specified in the multimedia control’s TimeFormat property (see “Setting a Multimedia Control’s Time Format” earlier in this chapter).

Let’s see an example. In this case, we’ll just play the first 10 seconds of a MID file, C:\windows\media\canyon.mid, which comes with Windows. First, we open that file when the form first loads, using a multimedia control, MMControl1, and set the control’s time format to mciFormatMilliseconds:

Private Sub Form_Load()
    MMControl1.TimeFormat = mciFormatMilliseconds
    MMControl1.FileName = "c:\windows\media\canyon.mid"
    MMControl1.Command = "Open"
End Sub

Now, when the user clicks a command button, Command1, we play the first 10 seconds of the file like this (although we’ve set the control’s time format to mciFormatMilliseconds, times in this format are actually measured in tenths of a second, which means that we set to From property to 100 for 10 seconds):

Private Sub Command1_Click()
    MMControl1.From = 0
    MMControl1.To = 100
    MMControl1.Command = "Play"
End Sub

And that’s it—now you can set the To and From locations in a multimedia file.


Previous Table of Contents Next


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.