Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
play sound when closing xcel 2007 Pirgnori Excel Discussion (Misc queries) 1 December 28th 09 09:21 PM
Play sound aac Excel Discussion (Misc queries) 2 December 5th 07 11:24 PM
Play Sound File Once when cell value condition id met John 1 Excel Discussion (Misc queries) 4 September 1st 07 04:32 PM
play sound when pressing commandbutton Hoyos Excel Discussion (Misc queries) 1 August 19th 07 04:12 PM
Using Countdown in Status Bar to Play Sound Full Monty Excel Programming 5 February 6th 04 05:37 PM


All times are GMT +1. The time now is 12:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"