|
|
Title | Play a WAV file repeatedly by using a For loop |
Keywords | sound, WAV, WaveAudio, MMC, continuous |
Categories | Multimedia, Controls |
|
|
Use a For loop to play the file. Each time through the loop, see if the user clicked Stop.
This program must wait for each play of the file to complete before it can see if the user clicked Stop so there may be a delay in stopping.
|
|
Private Sub Form_Load()
' Prepare the MCI control for WaveAudio.
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
End Sub
' Open the device and play the sound.
Private Sub cmdPlay_Click()
Dim i As Integer
If cmdPlay.Caption = "Stop" Then
' The user wants to stop.
cmdPlay.Caption = "Play"
Else
' The user wants to start.
cmdPlay.Caption = "Stop"
DoEvents
' Set the file name.
MMControl1.FileName = txtFile.Text
For i = 1 To 5
' Open the MCI device.
MMControl1.Wait = True
MMControl1.Command = "Open"
' Play the sound.
MMControl1.Wait = True
MMControl1.Command = "Play"
' Close the device.
MMControl1.Command = "Close"
' See if the user clicked Stop.
DoEvents
If cmdPlay.Caption = "Play" Then Exit For
Next i
cmdPlay.Caption = "Play"
End If
End Sub
|
|
|
|
|
|