使用mcisendstring重复播放音乐文件

思路:在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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值