Article ID: 109371
Article Last Modified on 5/6/2003
'******* Declarations Section *******
Option Compare Database
Option Explicit
Declare Function alias_mciSendString& Lib "MMSystem" alias_
"mciSendString" (ByVal Sound$, ByVal RtnString$,_
ByVal RtnLength%, ByVal Hndl%)
Dim RetInt As Integer
Dim RetStr As String * 64
Dim mciStatement As String
Global gTrackCurrent As Integer ' stores current track on CD.
Global gTrackCount As Integer ' stores count of tracks on CD.
'******* Play Function *********
Function CDPlay () As Integer
' This function initializes the audio device
' with the first call to mciSendString(), and
' then starts the CD playing with the second call.
RetInt = alias_mciSendString("Open CDAudio", "", 0, 0)
CDPlay = alias_mciSendString("Play CDAudio", "", 0, 0)
End Function
'******* Stop Function **********
Function CDStop () As Integer
' This function stops the CD with the first call
' to mciSendString(), and closes the audio device
' with the second call.
RetInt = alias_mciSendString("Stop CDAudio", "", 0, 0)
CDStop = alias_mciSendString("Close CDAudio", "", 0, 0)
End Function
'******** Previous Track Function **********
Function CDTrackPrevious ()
Dim TrackPrevious As Integer
' Set time format to Tracks, minutes, seconds, and frames.
RetInt = alias_mciSendString("Set CDAudio Time Format TMSF",_
"", 0, 0)
' Retrieve the track number that is currently playing, and
' the total number of tracks on the CD. Store these values
' in global variables so that they are available to the form.
mciStatement = "Status CDAudio Current Track"
RetInt = alias_mciSendString(mciStatement, RetStr, 63, 0)
gTrackCurrent = Val(RetStr)
TrackPrevious = gTrackCurrent - 1
mciStatement = "Status CDAudio Number of Tracks"
RetInt = alias_mciSendString(mciStatement, RetStr, 63, 0)
gTrackCount = Val(RetStr)
' Check to see if the current track is the first track. If it
' is seek to the beginning of the current track and play it.
' Otherwise, move to the previous track and play from there to
' the end of the CD.
If TrackPrevious > 0 Then
mciStatement = "Play CDAudio from " & TrackPrevious
mciStatement = mciStatement & " To " & gTrackCount
CDTrackPrevious = alias_mciSendString(mciStatement, "", 0, 0)
Else
mciStatement = "Seek CDAudio to " & TrackPrevious
RetInt = alias_mciSendString(mciStatement, "", 0, 0)
CDTrackPrevious = alias_mciSendString("Play CDAudio", "", 0, 0)
End If
End Function
'********** Next Track Function **********
Function CDTrackNext () As Integer
Dim TrackNext As Integer
' Set time format to Tracks, minutes, seconds, and frames.
RetInt = alias_mciSendString("Set CDAudio Time Format TMSF",_
"", 0, 0)
' Retrieve the track number that is currently playing, and
' the total number of tracks on the CD. Store these values
' in global variables so that they are available to the form.
mciStatement = "Status CDAudio Current Track"
RetInt = alias_mciSendString(mciStatement, RetStr, 63, 0)
gTrackCurrent = Val(RetStr)
TrackNext = gTrackCurrent + 1
mciStatement = "Status CDAudio Number of Tracks"
RetInt = alias_mciSendString(mciStatement, RetStr, 63, 0)
gTrackCount = Val(RetStr)
' Check to see if the current track is the last track. If it
' is seek to the beginning of the last track and play it.
' Otherwise, move to the next track and play from there to the end
' of the CD.
If (TrackNext) < gTrackCount Then
mciStatement = "Play CDAudio from " & TrackNext
mciStatement = mciStatement & " To " & gTrackCount
CDTrackNext = alias_mciSendString(mciStatement, "", 0, 0)
Else
mciStatement = "Seek CDAudio to " & gTrackCurrent
RetInt = alias_mciSendString(mciStatement, "", 0, 0)
CDTrackNext = alias_mciSendString("Play CDAudio", "", 0, 0)
End If
End Function
'********* Eject Function **********
Function CDEject () As Integer
' This function is not supported by all CD devices.
CDEject = alias_mciSendString("Set CDAudio Door Open", "", 0, 0)
End Function
'********* Pause Function **********
Function CDPause () As Integer
CDPause = alias_mciSendString("Stop CDAudio", "", 0, 0)
End Function
Additional query words: cdrom
Keywords: kbinfo kbprogramming KB109371