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


Setting File Information And Opening Files

The Testing Department is calling again. The new multimedia control you’ve added to your program looks really fine—but 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 name’s extension).

To specify which file you want to use with a multimedia control, you set that control’s FileName property, and to open that file (and so make the multimedia control’s buttons active so the user can play the file), you set the control’s Command property to “Open”. Let’s 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 control’s buttons are active, users can work with the file—for example, to play the file, they click the Play button.

Setting A Multimedia Control’s Time Format

Now that we’re 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:

  mciFormatMilliseconds—0; milliseconds are stored as a 4-byte integer variable.
  mciFormatHms—1; hours, minutes, and seconds are packed into a 4-byte integer. From least significant byte to most significant byte, the individual data values are as follows: Hours/Minutes/Seconds/Unused.
  mciFormatMsf—2; minutes, seconds, and frames are packed into a 4-byte integer. From least significant byte to most significant byte, the individual data values are as follows: Minutes/ Seconds/ Frames/Unused.
  mciFormatFrames—3; frames are stored as a 4-byte integer variable.
  mciFormatSmpte24—4; 24-frame SMPTE packs the following values in a 4-byte variable from least significant byte to most significant byte: Hours/ Minutes/Seconds/ Frames. SMPTE (Society of Motion Picture and Television Engineers) time is an absolute time format expressed in hours, minutes, seconds, and frames. The standard SMPTE division types are 24, 25, and 30 frames per second.
  mciFormatSmpte25—5; 25-frame SMPTE packs data into the 4-byte variable in the same order as 24-frame SMPTE.
  mciFormatSmpte30—6; 30-frame SMPTE packs data into the 4-byte variable in the same order as 24-frame SMPTE.
  mciFormatSmpte30Drop—7; 30-drop-frame SMPTE packs data into the 4-byte variable in the same order as 24-frame SMPTE.
  mciFormatBytes—8; bytes are stored as a 4-byte integer variable.
  mciFormatSamples—9; samples are stored as a 4-byte integer variable.
  mciFormatTmsf—10; tracks, minutes, seconds, and frames are packed in the 4-byte variable from least significant byte to most significant byte: Tracks/Minutes/Seconds/Frames.


WARNING!  As you might expect, not all formats are supported by every device. In practice, this means that if you try to set an invalid format, it is ignored.

Let’s 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 Control’s Status” later in this chapter) and the Position property, which holds the time that’s elapsed from the beginning of the file, displaying that time in a label, Label1.

You should know that although we’ve set the time to milliseconds, it’s actually only reported in tenths of a second (probably because the computer’s 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


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.