Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Play a CD Audio track

Total Hit ( 3578)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


If you want to play a track of an audio CD from VB you can use MCI functions. The main MCI function is mciSendString, that sends command strings to the system and execute them:

Click here to copy the following block
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal _
  lpstrCommand As String, ByVal lpstrReturnString As String, _
  ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

The first argument is the command string, lpstrReturnString receives return information (if needed), uReturnLength indicates the size, in characters, of lpstrReturnString, and hwndCallback is used for system notification. Remember that every command string described in this tip must be sent to the system with:

Click here to copy the following block
CommandString = "Your MCI command here"
RetVal = mciSendString(CommandString, vbNullString, 0, 0)

First you must open the CDAudio device with

Click here to copy the following block
CommandString = "Open cdaudio alias MyCDAudio"

"MyCDAudio" is an arbitrary name that you'll use in subsequent command strings as an alias of the filename. After opening the device you have to set the time format to a special mode called tracks/minutes/seconds/frames (TMSF): in this mode you can select a track indicating only its number, instead of the precise time location in on the CD:

Click here to copy the following block
CommandString = "Set MyCDAudio time format TMSF"

Now you can play the CD track with the command
' Play the Nth track

Click here to copy the following block
CommandString = "Play MyCDAudio from " & N & " to " & (N + 1) & " wait"

For example, to play the track number 4, the command string is
CommandString = "Play MyCDAudio from 4 to 5 wait"

The execution is synchronous, but you can play the file asynchronously and receive notifications replacing "wait" with "notify" and setting hwndCallback argument to the hWnd property of your form. In this case the system sends the form a MM_MCINOTIFY message when the playback is finished. To intercept this message you have to create a custom window procedure and use subclassing techniquews. With asynchronous executions, you can pause / resume and stop playback with:

Click here to copy the following block
' pause playing the track
CommandString = "Pause MyCDAudio"
' resume a paused track
CommandString = "Resume MyCDAudio"
' terminate playing the track
CommandString = "Stop MyCDAudio"

When you've finished to use the CDAudio device, you must close it with

Click here to copy the following block
CommandString = "Close MyCDAudio"


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.