Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitlePlay a WAV file repeatedly by using a Timer
Keywordssound, WAV, WaveAudio, MMC, continuous
CategoriesMultimedia, Controls
 
To play the file, start a timer. The timer checks the MMC control's Mode and, if the mode is mciModeStop, it plays the file.

The timer plays the sound asynchronously so the program can execute steps while the sound is playing. IN particular, it can stop the sound immediately.

 
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()
    If Timer1.Enabled Then
        Timer1.Enabled = False
        cmdPlay.Caption = "Play"

        ' Close the device.
        MMControl1.Command = "Close"
    Else
        Timer1.Enabled = True
        cmdPlay.Caption = "Stop"
    
        ' Set the file name.
        MMControl1.FileName = txtFile.Text

        ' Open the MCI device.
        MMControl1.Wait = True
        MMControl1.Command = "Open"
    End If
End Sub

Private Sub Timer1_Timer()
    ' See what mode the MCI control is in.
    If MMControl1.Mode = mciModeStop Then
        ' It's stopped. Play it again, Sam.
        MMControl1.Wait = True
        MMControl1.Command = "Prev"
        MMControl1.Command = "Play"
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated