How to play sound | C# .NET
HTML-код
- Опубликовано: 8 сен 2024
- How to play a sound in C# .NET.
What is the SoundPlayer Class?
The SoundPlayer class controls playback of a sound from a .wav file.
1. Define a new SoundPlayer pointing to your WAV file
2. Ensure the Wav file is located within the bin\Debug folder or bin\Debug
etcoreapp folder for console applications
3. Install the package System.Windows.Extensions and use the System.Media namespace
4. Tell the SoundPlayer variable to execute the PlaySync(); method
5. Run your program to play the Wav file
Short, exactly to the point, answers exactly the question asked. Subscribed.
If you want to loop it without the application freezing under sound.play(); type sound.PlayLooping(); this will loop the song.
Omg thank you Bro
wow i need more like this short and simple, Thanks :D
you knows what you are talking about and i respect that so i subscribe
thank you for your video! i have been finding this video for a long time! from VietNam with love!
My pleasure friend!
If you get warning CA1416. Edit your .csproj file with net5.0-windows Also you need to save sound file to net X.0-windows in bin,debug
Awesome sauce!🛸
Thank you! This was really helpful, if its possible, would you be able to demostrate the same thing but instead of playing a wav file open a image file?
When the sound plays, the program stops. I mean, I put lines of codes after the PlaySync(); method and there's only a black screen on the console application. How do I make it play whilst the other line of codes are running?
So I had this problem too, and from what I've found all you need to do is replace the 'PlaySync();' line with just 'Play();' , the only downside to this is the music won't loop the program anymore, and the application will end as soon as it runs out of instructions as normal, I'm not sure if there's a way to play the music infinitely and do all the instructions but this is the only fix I've found for now, hope this helps!
@@TheRealLyonic Under the line type sound.PlayLooping();
@@signaller Thanks!
Thank you so muchh!!
Thanks ❤❤❤❤❤❤
thanks man :D
Is there a way to stop a sound from playing?
Thank you man
THANKS !!!!
WELCOME !!!!
"System.IO.FileNotFoundException: Verify that there is an audio file in the specified location.'" Also I don't have the netcoreapp folder for some reason. anybody know how to fix?
bro help me
how to install the package
How can I change its volume? Does anyone know ???´
1:27 music pls?....
@@Tech_Ez Thank you!!!))))