|
-
Oct 7th, 2005, 04:57 AM
#1
Thread Starter
Fanatic Member
PlaySound - how to loop?
Ok, so I'm thick. But how on earth do I get this code to LOOP the sound so it keeps playing? I can't get it to work...
Code:
Option Explicit
Private Const SND_APPLICATION = &H80 ' look for application specific association
Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry
Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_FILENAME = &H20000 ' name is a file name
Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy
Private Const SND_PURGE = &H40 ' purge non-static events for task
Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom
Private Const SND_SYNC = &H0 ' play synchronously (default)
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
-
Oct 7th, 2005, 05:02 AM
#2
Re: PlaySound - how to loop?
Have you tried this?
VB Code:
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_ASYNC Or SND_LOOP
-
Oct 7th, 2005, 05:12 AM
#3
Thread Starter
Fanatic Member
Re: PlaySound - how to loop?
dee-u - thanks very much for replying - appreciate it.
Yes, I've tried that (and I just copy-pasted your code too) - the sound plays once and that's all. What am I missing...
-
Oct 7th, 2005, 05:14 AM
#4
Re: PlaySound - how to loop?
How about this? I really can't check it for now...
VB Code:
PlaySound "C:\WINDOWS\MEDIA\TADA.WAV", ByVal 0&, SND_FILENAME Or SND_LOOP
-
Oct 7th, 2005, 05:21 AM
#5
Thread Starter
Fanatic Member
Re: PlaySound - how to loop?
Sorry - just plays once again... hmmm.
And my daughter wanted me to put this picture in for you!
-
Oct 7th, 2005, 11:40 AM
#6
Re: PlaySound - how to loop?
The PlaySound API only plays one sound at a time and is very limited of its capabilities. You get a lack of control. So if you are making a game or a music app, it is better to use DirectSound or WAVEMIX32, for more control over your sound, and allow more than one sound to play at the same time. Here are some tutorials on DirectSound:
http://directx4vb.vbgamer.com/DirectX4VB/TUT_DX7_DS.asp
http://directx4vb.vbgamer.com/DirectX4VB/TUT_DX8_DA.asp
-
Oct 7th, 2005, 11:44 AM
#7
Thread Starter
Fanatic Member
Re: PlaySound - how to loop?
Thanks Jacob - but actually, I sorted it - it was because I was trying to leave out the Private bit in:
Code:
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
No doubt a very basic mistake on my part - but can some kind soul maybe explain why it's so critical?
-
Sep 14th, 2009, 01:53 PM
#8
New Member
Re: PlaySound - how to loop?
I tried that code but I get an error message in
Code:
Private Declare Function playsound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
for some reason. It says "Member already exists in a object module from which this object module derives."
Please help! Here is my code (exactly the same as everybody else has):
Code:
Option Explicit
Private Const SND_APPLICATION = &H80 ' look for application specific association
Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry
Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier
Private Const SND_ASYNC = &H1 ' play asynchronously
Private Const SND_FILENAME = &H20000 ' name is a file name
Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy
Private Const SND_PURGE = &H40 ' purge non-static events for task
Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom
Private Const SND_SYNC = &H0 ' play synchronously (default)
Private Declare Function playsound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
Private Sub Command1_Click()
'KPD-Team 2000
'URL: http://www.allapi.net/
'E-Mail: [email protected]
playsound "C:\Users\Bakke\Desktop\Teit\DrumLoop1.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
End Sub
Please help, I really need it. (I'm getting paid for it)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|