1. 在E:\FODDER\SOUND目录下准备五个WAV文件,文件名分别为:BK1.WAV--BK5.WAV。
2. 新建一个工程,在窗体中添加一个MMControl控件(?ο仍凇肮こ蹋考敝醒≡馦icrosoft Multimedia Control 5.0),一个Timer控件,其Interval属性设为5000。
3. 双击窗体,在代码窗口的对象下拉框中选择“(通用)”,添加代码Dim i As Integer。
4. 给Form的Load事件添加如下代码:
Private Sub Form_Load()
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
i = 1 注释:首先播放第一首音乐
If Not (MMControl1.Mode = mciModeNotOpen) Then
MMControl1.Command = "close"
End If
MMControl1.DeviceType = "waveaudio"
MMControl1.filename = "e:\fodder\sound\bk" & Trim(Str(i)) & ".wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
End Sub
5. 给Timer的Timer事件添加如下代码
Private Sub Timer1_Timer()
If MMControl1.Mode = 525 Then 注释:若一首乐曲放完,则放下一首
MMControl1.Command = "close"
i = i + 1
If i > 5 Then 注释:五首音乐放完,则循环
i = 1
End If
MMControl1.DeviceType = "waveaudio"
MMControl1.filename = "e:\fodder\sound\bk" & Trim(Str(i)) & ".wav"
MMControl1.Command = "open"
MMControl1.Command = "play"
End If
End Sub
6. 此外,你还可在容器或菜单中加一个背景音乐开关。
文章来源于领测软件测试网 https://www.ltesting.net/