|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Setting File Information And Opening FilesThe Testing Department is calling again. The new multimedia control youve added to your program looks really finebut how about that music you were going to play? Besides physical devices like MIDI devices and CD players, the multimedia control can play files from disk, such as AVI, MPG, WAV, and MID files. If you want to play or record a file in a recognized multimedia format, you can specify the file name the control is to work with without specifying the device type in the DeviceType property (the control gets the data format from the file names extension). To specify which file you want to use with a multimedia control, you set that controls FileName property, and to open that file (and so make the multimedia controls buttons active so the user can play the file), you set the controls Command property to Open. Lets see an example. Here, we set the file to work with to C:\windows\media\ding.wav (which comes with Windows) and then open that file, making the buttons of the multimedia control, MMControl1, active: Private Sub Form_Load() MMControl1.Notify = False MMControl1.Wait = True MMControl1.Shareable = False MMControl1.FileName = "C:\WINDOWS\MEDIA\DING.WAV" MMControl1.Command = "Open" End Sub When the multimedia controls buttons are active, users can work with the filefor example, to play the file, they click the Play button. Setting A Multimedia Controls Time FormatNow that were working with animations and sound playback, timing information becomes important, and we can set the time format (such as milliseconds) used in the multimedia control to specify timing information. In particular, the multimedia control supports these properties that access or send information in the current time format: From, Length, Position, Start, To, TrackLength, and TrackPosition. To set the time format for a multimedia control, use the TimeFormat property; this property indicates the timing units used by the control. This property can take these values:
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 (see Displaying the Multimedia Controls Status later in this chapter) and the Position property, which holds the time thats elapsed from the beginning of the file, displaying that time in a label, Label1. You should know that 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 location in the MID file this way:
Private Sub MMControl1_StatusUpdate()
Label1.Caption = Str(MMControl1.Position / 10)
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. |