|
|
Title | Play a WAV file asynchronously |
Keywords | sound, WAV, WaveAudio, MMC, asynchronously |
Categories | Multimedia, Controls |
|
|
Use the MMC control. Set it's Wait property to False (the default) before executing the Play command. The program continues executing while the file plays so you can click other buttons and so forth. In particular, you can stop the MMC from playing the WAV file.
|
|
Private Sub Form_Load()
' Prepare the MCI control for WaveAudio.
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.TimeFormat = mciFormatMilliseconds
End Sub
' Open the device and play the sound.
Private Sub cmdPlay_Click()
' Disable this button.
cmdPlay.Enabled = False
' Set the file name.
MMControl1.FileName = txtFilename.Text
' Open the MCI device.
MMControl1.Wait = True
MMControl1.Command = "Open"
' Play the sound without waiting.
MMControl1.Notify = True
MMControl1.Wait = False
MMControl1.Command = "Play"
' Enable the timer.
tmrSound.Enabled = True
cmdStop.Enabled = True
End Sub
Private Sub cmdStop_Click()
' Stop playing.
MMControl1.Wait = True
MMControl1.Command = "Stop"
End Sub
Private Sub Form_Load()
' Prepare the MCI control for WaveAudio.
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.TimeFormat = mciFormatMilliseconds
End Sub
' Close the device when the sound is done.
Private Sub MMControl1_Done(NotifyCode As Integer)
' Close the device.
MMControl1.Command = "Close"
' Disable the timer.
tmrSound.Enabled = False
cmdStop.Enabled = False
' Reenable the button.
cmdPlay.Enabled = True
End Sub
' Display the time through the sound clip.
Private Sub tmrSound_Timer()
lblEllapsed.Caption = Format$(MMControl1.Position)
End Sub
|
|
|
|
|
|