How to Seek a CD Track by Using the MCI Control

Last reviewed: June 21, 1995
Article ID: Q112732
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 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 reference words: 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: PrgOther


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.