MCI Control Problem

kennethp used Ask the Experts™
Hey there!
Can anyone tell me PLZ why my .wav file just plays once?
This is my code:

formLoad event:

    MMControl1.FileName = App.Path & "\sounds\zoop3.wav"
    MMControl1.Command = "Open"

playClick event:

    MMControl1.Command = "Rewind"
    MMControl1.Command = "Play"

What's wrong with it? I want my sound to play everytime I click a button, what should I do?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I find it easier to use the Multimedia API for playing sounds and movies.  Just open a new VB Project and add a command button to Form1, then paste this code in the form. Then just run it and click the command button..  Tada !

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 Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Private lReturn As Long

Private Sub Command1_Click()
End Sub

Private Sub PlaySound()
    lReturn = mciSendString("PLAY MySound FROM 0", 0&, 0, 0)
End Sub

Private Sub OpenSound(ByVal sFile As String)
    Dim ShortPath As String
    If InStr(sFile, "\") = 0 Then
        sFile = App.Path & "\" & sFile
    End If

    ShortPath = Space$(255)
    GetShortPathName sFile, ShortPath, Len(ShortPath)
    ShortPath = Left$(ShortPath, Len(Trim$(ShortPath)) - 1)
    lReturn = mciSendString("OPEN " & ShortPath & " TYPE WAVEAUDIO ALIAS MySound", 0&, 0, 0)
End Sub

Private Sub CloseSound()
    lReturn = mciSendString("Close MySound", 0&, 0, 0)
End Sub

Private Sub Form_Load()
    OpenSound App.Path & "\sounds\zoop3.wav"
End Sub

Private Sub Form_Unload(Cancel As Integer)
End Sub
Author of the Year 2009

Hi kennethp,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept johnsand's comment(s) as an answer.

kennethp, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial