Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW TO PLAY SOUND.WAV FILES SIMULTANEOUSLY UNDER EXCEL
I have a requirement to trigger 3 sound effects during execution of an Excel
macro. When the Workbook opens, Function Keys are assigned to each Sound procedure as follows: Option Explicit Private Sub Workbook_Open() ' ASSIGN FUNCTION KEYS Application.OnKey "{F1}", "Sound1" Application.OnKey "{F2}", "Sound2" Application.OnKey "{F3}", "Sound3" End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) ' RESET FUNCTION KEYS Application.OnKey "{F1}" Application.OnKey "{F2}" Application.OnKey "{F3}" End Sub The following Windows API function declarations appear in the Module code: 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_ASYNC = &H1 Private Const SND_FILENAME = &H20000 The individual Sound procedures a Public Sub Sound1() Call PlaySound(ThisWorkbook.Path & "\sound1.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound2() Call PlaySound(ThisWorkbook.Path & "\sound2.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound3() Call PlaySound(ThisWorkbook.Path & "\sound3.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub When F1 is pressed, sound1.wav file plays, and similarly when F2 and F3 are pressed, the corresponding sound2.wav and sound3.wav files play. So far, so good. If a second sound file is triggered before the first one has finished playing, the first one is abandoned, and the second plays alone. What I want is to allow more than one sound file to be triggered and play to completion without being interrupted. Is there way of achieving this, perhaps involving a different Windows API function declaration? Or would 3 Sound Cards be needed to play the wav files completely independently? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW TO PLAY SOUND.WAV FILES SIMULTANEOUSLY UNDER EXCEL
Hi Hotbird,
PlaySound will not play WAV files simultaneously. As you've discovered, when you start a new sound, any current sounds will stop. It looks like you may have to use the mcisendstring API call to do this. Do a search in google, and you'll get lots of results back. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Hotbird wrote: I have a requirement to trigger 3 sound effects during execution of an Excel macro. When the Workbook opens, Function Keys are assigned to each Sound procedure as follows: Option Explicit Private Sub Workbook_Open() ' ASSIGN FUNCTION KEYS Application.OnKey "{F1}", "Sound1" Application.OnKey "{F2}", "Sound2" Application.OnKey "{F3}", "Sound3" End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) ' RESET FUNCTION KEYS Application.OnKey "{F1}" Application.OnKey "{F2}" Application.OnKey "{F3}" End Sub The following Windows API function declarations appear in the Module code: 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_ASYNC = &H1 Private Const SND_FILENAME = &H20000 The individual Sound procedures a Public Sub Sound1() Call PlaySound(ThisWorkbook.Path & "\sound1.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound2() Call PlaySound(ThisWorkbook.Path & "\sound2.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound3() Call PlaySound(ThisWorkbook.Path & "\sound3.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub When F1 is pressed, sound1.wav file plays, and similarly when F2 and F3 are pressed, the corresponding sound2.wav and sound3.wav files play. So far, so good. If a second sound file is triggered before the first one has finished playing, the first one is abandoned, and the second plays alone. What I want is to allow more than one sound file to be triggered and play to completion without being interrupted. Is there way of achieving this, perhaps involving a different Windows API function declaration? Or would 3 Sound Cards be needed to play the wav files completely independently? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW TO PLAY SOUND.WAV FILES SIMULTANEOUSLY UNDER EXCEL
Thanks for this explanation. I have searched Google for MCISendString, and
found examples which allow a WAIT parameter to be specified which ensures that a playing file is not interrupted. So far, however, I have not seen any references to multiple wav or midi files playing simultaneously and independently. Has anyone experience of doing this? "Jake Marx" wrote: Hi Hotbird, PlaySound will not play WAV files simultaneously. As you've discovered, when you start a new sound, any current sounds will stop. It looks like you may have to use the mcisendstring API call to do this. Do a search in google, and you'll get lots of results back. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Hotbird wrote: I have a requirement to trigger 3 sound effects during execution of an Excel macro. When the Workbook opens, Function Keys are assigned to each Sound procedure as follows: Option Explicit Private Sub Workbook_Open() ' ASSIGN FUNCTION KEYS Application.OnKey "{F1}", "Sound1" Application.OnKey "{F2}", "Sound2" Application.OnKey "{F3}", "Sound3" End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) ' RESET FUNCTION KEYS Application.OnKey "{F1}" Application.OnKey "{F2}" Application.OnKey "{F3}" End Sub The following Windows API function declarations appear in the Module code: 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_ASYNC = &H1 Private Const SND_FILENAME = &H20000 The individual Sound procedures a Public Sub Sound1() Call PlaySound(ThisWorkbook.Path & "\sound1.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound2() Call PlaySound(ThisWorkbook.Path & "\sound2.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound3() Call PlaySound(ThisWorkbook.Path & "\sound3.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub When F1 is pressed, sound1.wav file plays, and similarly when F2 and F3 are pressed, the corresponding sound2.wav and sound3.wav files play. So far, so good. If a second sound file is triggered before the first one has finished playing, the first one is abandoned, and the second plays alone. What I want is to allow more than one sound file to be triggered and play to completion without being interrupted. Is there way of achieving this, perhaps involving a different Windows API function declaration? Or would 3 Sound Cards be needed to play the wav files completely independently? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
HOW TO PLAY SOUND.WAV FILES SIMULTANEOUSLY UNDER EXCEL
Hmmm...I've never done this, so maybe MCISendString is not the way to go.
The DirectX platform would be much more robust, but it's a lot more complex than PlaySound. Here's a link to get you started: http://216.5.163.53/DirectX4VB/Tutor...DA_SoundFx.asp You would have to set a reference in your project to the DirectX 8.0 library. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Hotbird wrote: Thanks for this explanation. I have searched Google for MCISendString, and found examples which allow a WAIT parameter to be specified which ensures that a playing file is not interrupted. So far, however, I have not seen any references to multiple wav or midi files playing simultaneously and independently. Has anyone experience of doing this? "Jake Marx" wrote: Hi Hotbird, PlaySound will not play WAV files simultaneously. As you've discovered, when you start a new sound, any current sounds will stop. It looks like you may have to use the mcisendstring API call to do this. Do a search in google, and you'll get lots of results back. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Hotbird wrote: I have a requirement to trigger 3 sound effects during execution of an Excel macro. When the Workbook opens, Function Keys are assigned to each Sound procedure as follows: Option Explicit Private Sub Workbook_Open() ' ASSIGN FUNCTION KEYS Application.OnKey "{F1}", "Sound1" Application.OnKey "{F2}", "Sound2" Application.OnKey "{F3}", "Sound3" End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) ' RESET FUNCTION KEYS Application.OnKey "{F1}" Application.OnKey "{F2}" Application.OnKey "{F3}" End Sub The following Windows API function declarations appear in the Module code: 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_ASYNC = &H1 Private Const SND_FILENAME = &H20000 The individual Sound procedures a Public Sub Sound1() Call PlaySound(ThisWorkbook.Path & "\sound1.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound2() Call PlaySound(ThisWorkbook.Path & "\sound2.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub Private Sub Sound3() Call PlaySound(ThisWorkbook.Path & "\sound3.wav", 0&, SND_ASYNC Or SND_FILENAME) End Sub When F1 is pressed, sound1.wav file plays, and similarly when F2 and F3 are pressed, the corresponding sound2.wav and sound3.wav files play. So far, so good. If a second sound file is triggered before the first one has finished playing, the first one is abandoned, and the second plays alone. What I want is to allow more than one sound file to be triggered and play to completion without being interrupted. Is there way of achieving this, perhaps involving a different Windows API function declaration? Or would 3 Sound Cards be needed to play the wav files completely independently? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
play sound when closing xcel 2007 | Excel Discussion (Misc queries) | |||
Play sound | Excel Discussion (Misc queries) | |||
Play Sound File Once when cell value condition id met | Excel Discussion (Misc queries) | |||
play sound when pressing commandbutton | Excel Discussion (Misc queries) | |||
Using Countdown in Status Bar to Play Sound | Excel Programming |