思路:在TIMER控件中检测当前文件的播放状态,如果为stopped,那么就重复播放
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 100
Call mciSendString("close all", 0, 0, 0) '首先关闭所有的MCI设备,避免播放多个音乐文件时声音会重叠
Call mciSendString("open " + "c:/winnt/media/ringin.wav", 0, 0, 0) '打开MCI设备
Call mciSendString("play " + "c:/winnt/media/ringin.wav", 0, 0, 0) '播放MCI设备
End Sub
Private Sub Timer1_Timer()
Dim buffer As String * 128
Dim pos As Integer
mciSendString "status c:/winnt/media/ringin.wav mode", buffer, 128, 0&
pos = InStr(buffer, Chr(0))
If Left(buffer, pos - 1) = "stopped" Then
Call mciSendString("close all", 0, 0, 0)
Call mciSendString("open " + "c:/winnt/media/ringin.wav", 0, 0, 0)
Call mciSendString("play " + "c:/winnt/media/ringin.wav", 0, 0, 0)
End If
End Sub