''''声明 Private Declare Function mciSendString Lib "winmm.dll" Alias _ "mciSendStringA" (ByVal lpstrCommand As String, ByVal _ lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal _ hwndCallback As Long) As Long Dim i As Integer Private Sub playsound(FileName As String) Dim ret As Integer ret = mciSendString("close MyWav", 0&, 0, 0) Select Case UCase(Right(FileName, 3)) Case "WAV" ret = mciSendString("open " & FileName & " type WAVEAudio alias MyWav", 0&, 0, 0) Case "MID" ret = mciSendString("open " & FileName & " type Sequencer alias MyWav", 0&, 0, 0) Case "AVI" ret = mciSendString("open " & filename & " type AVIvideo alias MyWav", 0&, 0, 0) Case "CDA" ret = mciSendString("open " & filename & " type CDaudio alias MyWav", 0&, 0, 0) Case Else ret = mciSendString("open " & FileName & " alias MyWav", 0&, 0, 0) End Select ret = mciSendString("play MyWav", 0&, 0, 0) End Sub Private Sub Timer3_Timer() Dim s As String s = String(256, Chr(0)) Call mciSendString("status MyWav mode", s, Len(s), 0) If InStr(1, s, "stop", vbTextCompare) Then playsound filename End If End Sub 调用:playsound music.mid
|