|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Immediate SolutionsUsing The Animation ControlVisual Basic comes with an animation control, and well start our multimedia operations by taking a look at this control. This control is smaller than the multimedia control and takes up fewer system resources, but its very restricted. The animation control can only play AVI files, and those without sound at that. In addition, the animation control can display only uncompressed AVI files or AVI files that have been compressed using run-length encoding (RLE).
This control is useful because you can play AVI files in it directly, without using another control (for example, the multimedia control uses a picture box to play animations). The control allows you to create buttons or other objects that display animations when clicked. For example, the File Copy progress bar in Windows 95 uses an animation control; as youve probably seen, pieces of paper fly from one folder to another while the copy operation is in progress, and thats supported with an animation control. Heres how you add an animation control to a program:
To display an AVI file, you use the controls Open method to open that file, passing the file name as the single argument to Open. After youve opened the file to play, you can use the Play method to play the file: AnimationControl.Play ([ varRepeatCount] [,varStartFrame] [,varEndFrame]) You can also set the controls AutoPlay property to True to make the control play the AVI file as soon as it opens that file. Heres an example in which we set AutoPlay to True for an animation control, Animation1:
Private Sub Command1_Click()
Animation1.AutoPlay = True
...
End Sub
Then we open and play an AVI file, animation3.avi:
Private Sub Command1_Click()
Animation1.AutoPlay = True
Animation1.Open "animation3.avi"
End Sub
The animation control is relatively lightweight, so you can add it to your programs without taking up many system resources, but the limits of this control are severe. If you want to play AVI files with sound or other types of files, look into the multimedia control topics coming up in this chapter. Adding A Multimedia Control To A ProgramThe Aesthetic Design Department is calling again. Users of your program, SuperDuperDataCrunch, get pretty tense around tax time while computing their taxes using that program. Wouldnt it be great if your program could play some soothing music in the background? Well, you say dubiously, if you really want to. You can let your program play sounds (WAV files, MID files, or even the CD in the computers CD drive) using the multimedia control, and well see how to add that control to a program now. Just follow these steps:
Now that youve added a multimedia control to your program, see the following few topics on how to configure and use it in code. Setting The Device Type And Opening The DeviceNow that youve added a multimedia control, how do you indicate what kind of multimedia device you want to open? And how do you open it? Does opening the device make the buttons in the multimedia control active? You can use the controls DeviceType property to set the type of device you want to work with. You set this property when youre opening an actual device such as a CD drive, or when the name of the file youre working with (see the following topic, Setting File Information) does not indicate the format of the multimedia data. Note that you do not need to set the DeviceType property when playing files in recognized file formats like WAV, MID, AVI, MPG, and so on. Here are the different strings you can set the DeviceType property to, one for all the device types the multimedia control supports:
You set the DeviceType property before opening the device with the Open command. To use the Open command, you set the multimedia controls Command property to Open. Lets see an example. Here, we open a music CD in the computers CD-ROM drive, connecting it to the multimedia control MMControl1 when in the Form_Load event and then opening that device:
Private Sub Form_Load()
MMControl1.TimeFormat = MCI_FORMAT_TMSF
MMControl1.DeviceType = "CDAudio"
MMControl1.Command = "Open"
End Sub
If there is a CD in the CD drive, the multimedia controls buttons become active after executing this code and the user can play the CD (if your version of Windows has AutoPlay enabled, you might have to hold down the shift key while inserting the CD to make sure the Windows CD player does not come up automatically).
|
|
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. |