Loops aren't workin for PlaySound! aaahhh whhhyy!

Diablicolic

Well-known member
Joined
Jul 28, 2003
Messages
168
Location
Your Neighbor
Ok! Now when I play my sound, it doesnt loop even though I added the loop stuff:

Code:
Const SND_LOOP As Integer = &H8

And here is the code that makes the sound Alarm.wav:

Code:
		Sound.PlaySound("Data/Sounds/Alarm.wav", 0, SND_LOOP Or SND_SYNC)

The sound doesnt seem to loop even though it did with the previous version of PlaySound. Im pretty sure I didnt add any code to stop it, or have any sounds that would destroy that current sound.

It plays once and then just stops! Somebody help me!
 
Youre passing SND_SYNC which means the method would not return until the sound has finished playing. If the sound were being looped it would never finish and so the method would never return. The application would hang indefinitely at this point. Try using SND_ASYNC instead.
 
I tried that but it still doesnt loop, something tells me Im doing something bad on form load. Because the music plays when the form is opening, and then when the form is fully opened and all of the images are there it stops. I have another question about PlaySound:

Code:
PlaySound(Nothing, 0, SND_PURGE)

What is the 0 for? I just put 0 there all of the time

-------------

hahaha, whenever I put:

Code:
Sound.PlaySound("Data/Sounds/Alarm.wav", 0, SND_LOOP)

ANYWHERE, it freezes everything! What is goin on?!
 
Last edited by a moderator:
These are my tags at the top of the class!

Code:
Private Const SND_SYNC = &H0	 // Play sound at the same time together
Private Const SND_ASYNC = &H1	  // Play sound once at a time
Private Const SND_NODEFAULT = &H2	  // Silence if the sound sound is not found
Private Const SND_MEMORY = &H4	  // Points to a sound in memory
Private Const SND_LOOP = &H8	  // Loop the sound
Private Const SND_NOSTOP = &H10	 // DonAs Integer t stop the current sound
Private Const SND_NOWAIT = &H2000	  // DonAs Integer t wait if the driver is busy ??
Private Const SND_ALIAS = &H10000	  // Name is a Registry alias
Private Const SND_ALIAS_ID = &H110000	 // Alias is a predefined ID
Private Const SND_FILENAME = &H20000	 // Name is a file name
Private Const SND_RESOURCE = &H40004	 // Name is resource name or atom
Private Const SND_PURGE = &H40	 // Purge non-static events for task ??
Private Const SND_APPLICATION = &H80	   // Look for application-specific association
 
Last edited by a moderator:
In the WinApi 0 usually just means that parameter is not used or null.

You have to be careful when using the WinApi. I have had the computer totally reboot without warning when using BitBlt.
 
Obviously you didnt even read Squirms post:
Code:
Sound.PlaySound("Data/Sounds/Alarm.wav", 0, SND_LOOP Or SND_ASYNC)
You need the ASYNC flag.
 
What is the 0 for? I just put 0 there all of the time

If you read MSDN, youll see that the second parameter for PlaySound is a handle to the module which contains the sound resource, if playing from resource. Since you arent playing from resource, this should be zero.
 
Originally posted by VolteFace
Obviously you didnt even read Squirms post:
Code:
Sound.PlaySound("Data/Sounds/Alarm.wav", 0, SND_LOOP Or SND_ASYNC)
You need the ASYNC flag.

No no I did, I tried ASYNC, SYNC, Just Loop, etc etc. I did read Squirms post but I guess I didnt tell you guys that I tried a whole bunch of other ways including ASYNC.

But since I already had a MySound Class on my other C# Project (because I had two projects), I used that class instead at which is the same thing except just in C#. Thank yall for your help! :)
 
Back
Top