Re: Multimedia MCI control doesn't "Back"




"Wyne" <Wyne@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:0A8E6189-91A0-4A77-B6B1-DEA687DDD5AF@xxxxxxxxxxxxxxxx
> Hello,
>
> I want to use a a Multimedia MCI control to continuously play a warning
> sound. One command button, named "Start", is placed on the Form. The .wav
> file is opened in Form_load event. When Start button is clicked, it issue
> a
> "Play" command. When the Form receive a Done event, it issue a "Back"
> command
> followed by a "Paly" command.
>
> This program works only once (the beginning), then no more sound.
>
> Can any one tell me how to repeat a sound continuously?

Drop the MCI control. You don't need it. Instead, use the PlaySound
Win32API function. Here's an example. Add 2 command buttons to a form and
name them cmdPlay and cmdStop. Provide appropriate captions for each. Copy
and paste this code into General Declarations:

-----BEGIN CODE
Option Explicit

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal
lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Const SND_FILENAME As Long = &H20000 ' name is a file name
Private Const SND_LOOP As Long = &H8 ' loop the sound until next
sndPlaySound
Private Const SND_ASYNC As Long = &H1 ' play asynchronously
Private Const SND_ALIAS As Long = &H10000 ' name is a WIN.INI
[sounds] entry
Private Const SND_NODEFAULT As Long = &H2 ' silence not default, if
sound not found

Private Declare Function GetWindowsDirectory Lib "kernel32" Alias
"GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As
Long
Private Const MAX_PATH As Long = 260

Private Function GetWinDir() As String

Dim sBuffer As String
Dim lBufferSize As Long

lBufferSize = MAX_PATH
sBuffer = String$(lBufferSize, vbNullChar)
Call GetWindowsDirectory(sBuffer, lBufferSize)

GetWinDir = Left$(sBuffer, InStr(1, sBuffer, vbNullChar) - 1)

End Function

Private Sub cmdPlay_Click()

Dim sWinDir As String
Dim sWavFile As String

sWinDir = GetWinDir
If Right$(sWinDir, 1) <> "\" Then
sWavFile = sWinDir & "\media\ding.wav"
Else
sWavFile = sWinDir & "media\ding.wav"
End If

Call PlaySound(sWavFile, 0&, SND_ASYNC Or SND_LOOP Or SND_NODEFAULT)

End Sub

Private Sub cmdStop_Click()

Call PlaySound(vbNullString, 0&, SND_ASYNC)

End Sub
-----END CODE

--
Mike
Microsoft MVP Visual Basic


.