how can i stop looping sound in c# (visual studio)

if (ConditionTrue)
            {
                SoundPlayer simpleSound = new SoundPlayer(@"C:\Users\BIB HUTI\Desktop\beep.wav");
                simpleSound.Play();
            }



       // it keeps playing and never stops.

Recommended Answers

Your code will not loop the sound! is this code placed inside a loop? if yes add break; to it.

Jump to Post

Use a stop button or something of the like and use the Stop() method.
simpleSound.Stop();

Jump to Post

All 5 Replies

Your code will not loop the sound! is this code placed inside a loop? if yes add break; to it.

Use a stop button or something of the like and use the Stop() method.
simpleSound.Stop();

sorry but i need to play a sound at a specific time ( 12:00 AM). It played but didn't stop playing. Moreover, it's like an alarm and i dont want to use a button for that.

Ok since you are using time to start your sound, add the stop code and initiate it at let's say 12:01AM fair enough?

Thanks buddy . I never thought that way

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.