Private Sub cmdPlay_Click()
Dim cmd As String
Dim ret As Long
Dim buf As String
Dim pos As Integer
' Open the file.
cmd = "open waveaudio!" & _
txtFile.Text & " alias myaudio wait"
ret = mciSendString(cmd, vbNullString, 0, 0)
If ret <> 0 Then
buf = Space$(1024)
mciGetErrorString ret, buf, Len(buf)
pos = InStr(buf, Chr$(0))
buf = Left$(buf, pos - 1)
MsgBox buf
Exit Sub
End If
' Play the file.
cmd = "Play myaudio wait"
ret = mciSendString(cmd, vbNullString, 0, 0)
If ret <> 0 Then
buf = Space$(1024)
mciGetErrorString ret, buf, Len(buf)
pos = InStr(buf, Chr$(0))
buf = Left$(buf, pos - 1)
MsgBox buf
Exit Sub
End If
' Close the file.
cmd = "close myaudio wait"
ret = mciSendString(cmd, vbNullString, 0, 0)
If ret <> 0 Then
buf = Space$(1024)
mciGetErrorString ret, buf, Len(buf)
pos = InStr(buf, Chr$(0))
buf = Left$(buf, pos - 1)
MsgBox buf
Exit Sub
End If
End Sub
|