Yes I played a wave file through playsound api

invoke PlaySound,1001,hInstance,SND_RESOURCE

I inserted this function in the message loop


.WHILE TRUE
invoke PlaySound,1001,hInstance,SND_RESOURCE
invoke GetMessage, ADDR msg,NULL,0,0

Now my application does not start instead it just hangs till the sound is playing.As soon as the sound is over it is all ok.Please tell me where i am wrong.

Now when I put the playsound api in the Window procedure(just after th WM_CREATE message) instead of message loop the application starts but again no responding window appears as long as song is playing.


Why during the playsound api call the application hangs?
Posted on 2006-03-30 13:17:38 by lonelyboy
I don't do much with audio (or video for that mater); but I'm pretty sure that PlaySound has to finish executing before you can continue. There are several options to have to sound play while the window loads up. First would be to place the call to PlaySound within a thread handler and use BeginThread to launch the thread handler (so it runs while the normal windows procedure runs as a seperate thread). Another idea would be to add the call to a DLL which gets loaded at runtime (also has it run in a seperate thread). And final way (and probably the recommended way) would be to use mciSendString with the notify flag set.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/htm/_win32_mcisendstring.asp

Regards,
Bryant Keller
Posted on 2006-03-30 13:53:18 by Synfire
I don't know about putting it into the MessageLoop. (Do you know that the MessageLoop is called a lot of times every second? A lot.

But anyway, what you should be looking for is following:

invoke Playsound, 100, hInstance, SND_ASYNC OR SND_RESOURCE
Posted on 2006-03-30 19:58:59 by JimmyClif
That worked mr Jimmy.Thanks alot  :D
Posted on 2006-03-30 23:00:22 by lonelyboy
i am not yet involved  with threads yet but ya thanks alot for those invaluable tips Mr synfire
:D  :D  :D  :D  :D  :D  :D  :D
Posted on 2006-03-30 23:01:47 by lonelyboy
I recommend taking it OUT of the message loop. Windows sends many, many, many messages to your app (esp. at app's startup). The fact that it 'crashed' is that it had to be played many,many,many times. Now that you gave it the ASYNC attribute, it's being called, ignored (since it's most probably already playing), and the function returns. Such approach is VERY bad, becuase this way it's being called like 100 times, 99 of which are useless. If you don't know sound's length, then you can call the function on a fixed interval (say 1000ms) using a timer (please specify a function for it - don't use the message system). If you know sound's length, then call the function right after the sound stops.
Posted on 2006-03-31 07:59:21 by ti_mo_n

There are several options to have to sound play while the window loads up.


I think Synfire was getting at was specifically playing a sound while the window loads up. His suggestion could be used in conjunction with WM_CREATE if the program requires more initialization than the standard window/program.
Posted on 2006-03-31 08:14:11 by SpooK
I recommend taking it OUT of the message loop. Windows sends many, many, many messages to your app (esp. at app's startup). The fact that it 'crashed' is that it had to be played many,many,many times. Now that you gave it the ASYNC attribute, it's being called, ignored (since it's most probably already playing), and the function returns. Such approach is VERY bad, becuase this way it's being called like 100 times, 99 of which are useless. If you don't know sound's length, then you can call the function on a fixed interval (say 1000ms) using a timer (please specify a function for it - don't use the message system). If you know sound's length, then call the function right after the sound stops.



Yes you are right.I have already removed it from the message loop and put it in the WM_COMMAND message of play command in the dropdown menu
Posted on 2006-03-31 12:17:26 by lonelyboy