using System.Media; // ... SoundPlayer player = new SoundPlayer(@"C:\path\to\sound.wav"); player.Play();
using System.Media; using Properties; // namespace of your application's Properties // ... SoundPlayer player = new SoundPlayer(Properties.Resources.sound); player.Play();
using System.Media; // ... SoundPlayer player = new SoundPlayer(@"C:\path\to\sound.wav"); player.PlayAsync();In all of these examples, the `Play()` method starts playing the sound file synchronously, blocking the calling thread until the playback is finished. The `PlayAsync()` method starts playing the sound file asynchronously, allowing the calling thread to continue executing while the audio is playing. Overall, the System.Media SoundPlayer class provides a straightforward way to play audio files in C# without requiring any third-party packages.