How to Seek a CD Track by Using the MCI Control

ID: Q112732


The information in this article applies to:
  • Microsoft Visual Basic Standard and Professional Editions for Windows, versions 2.0, 3.0


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.

  1. Start a new project in Visual Basic. Form1 is created by default.


  2. Add an MCI Control (MMControl1) to Form1.


  3. Place the following code in the Form_Load event of Form1:
    
       Sub Form_Load()
          MMControl1.DeviceType = "CDAudio"
          MMControl1.Command = "Open"
       End Sub 


  4. 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 


  5. 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.


REFERENCES

For more information, see the Multimedia Programmer's Reference, CDAudio.

Additional query words: 2.00 3.00

Keywords :
Version :
Platform :
Issue type :


Last Reviewed: September 1, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.