Microsoft KB Archive/112732

= How to Seek a CD Track by Using the MCI Control =

Article ID: 112732

Article Last Modified on 12/9/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q112732



SUMMARY
The MCI Control supports seeking a certain Track by using the Commmand and To properties. In order to seek to a specific track, specify which track in the To property of the MCI Control. Then, using the Command property, perform the seek. This article gives an example.



MORE INFORMATION
The To property of the MCI Control will allow the seek to move to another position based on the current time format. If you set the TimeFormat property to MCI_FORMAT_TMSF (10), it will allow you to move to the beginning of specific tracks.

Step-by-Step Example
The following example shows how to seek through all tracks on a CD and play them for five seconds with the MCI Control.

 Start a new project in Visual Basic. Form1 is created by default. Add an MCI Control (MMControl1) to Form1.  Place the following code in the Form_Load event of Form1: Sub Form_Load MMControl1.DeviceType = "CDAudio" MMControl1.Command = "Open" End Sub   Add the following code to the Command1_Click event: Sub Command1_Click ' Set the timeformat to allow seek to move between tracks: mmcontrol1.TimeFormat = 10 ' Loop through all tracks and play each for five seconds: For i = 1 To MMControl1.Tracks MMControl1.To = Str$(i) MMControl1.Command = "Seek" MMControl1.Command = "Play" x = Timer While Timer < x + 5 DoEvents Wend Next ' Stop the CD: MMControl1.Command = "pause" End Sub  Run the program. The MCI Control should start playing Track 2

NOTE: Before starting this program, a CD must be inserted and ready to play. Therefore, you should add code to detect when a CD has been inserted and then run the above code.

