Click here to Skip to main content
15,906,218 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a big issue and i need ur help genious guiders

i want to play sound in my application
a wav file after another using playsound api

but idont know wat flags i must use right

the code used

C#
[DllImport("winmm.dll")]
        private static extern bool PlaySound(string filename, int module, int snd_flg);
        
<blockquote class="FQ">
        private const int SND_SYNC = 0x0000;
       private const int SND_ASYNC = 0x0001;
       private const int SND_NODEFAULT = 0x0002;
       private const int SND_MEMORY = 0x0004;// SND_LOOP
       private const int SND_LOOP = 0x0008;
       private const int SND_NOSTOP = 0x0010;
       private const int SND_PURGE = 0x40;
       private const int SND_APPLICATION = 0x80;
       private const int SND_NOWAIT = 0x00002000;
       private const int SND_ALIAS = 0x00010000;
       private const int SND_ALIAS_ID = 0x00110000;
       private const int SND_FILENAME = 0x00020000;



      <blockquote class="FQ"><div class="FQA">Quote:</div>PlaySound(Application.StartupPath + @"\wavs\patient_no.wav", 0, SND_SYNC );

               for (int i = 0; i < wav_arr.Length - 1; i++)
               {
                 PlaySound(Application.StartupPath + @"\wavs\" + wav_arr[i] + ".wav", 0, SND_SYNC);
              }
                PlaySound(Application.StartupPath + @"\wavs\go_to_lab.wav", 0, SND_SYNC | SND_NODEFAULT | SND_PURGE);

                //PlaySound(null, 0, SND_PURGE);
</blockquote>  


  </blockquote>



when i use async... the program doesn't stop >>like timers ,, but it returns only the last sound
and if i use sync the program stops till sound finished

how can i fix it

it's a problem wth flags
but dont know which will work just perfect an dont hang my app

thanx alot
Posted
Comments
Sergey Alexandrovich Kryukov 4-Oct-13 20:03pm    
The problem is your question tag: add .NET, C#. You are the one who is interested in that the most.
—SA
eng.iris 5-Oct-13 11:18am    
thanks --SA

1 solution

I'm assuming that this is C#...

Skip the unmanaged code, just use System.Media.SoundPlayer[^] which will play the sound in a separate thread without "locking up" your application.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 4-Oct-13 20:02pm    
Exactly, a 5.
—SA
Ron Beyer 4-Oct-13 20:32pm    
Thanks Sergey.
eng.iris 5-Oct-13 11:20am    
i tried it too but sound seems to hang when using sync
and when using async it played the last code

i am gonna be crazy

plz help
Ron Beyer 5-Oct-13 11:25am    
Sync means it blocks until the sound completes, thats pretty much the definition of synchronous. In order to play the sound and continue on with the application (aka not locked) then you have to play it asynchronous (async).
eng.iris 5-Oct-13 14:56pm    
yes i kow that , but why in the async mode it plays only the last wav audio

i tried to use thread.sleep after each sound played but thread.sleep stop the program too

is there a hint that could help me

thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900