Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

c# - How to play WAV audio file from Resources?

How can I play a WAV audio file in from my project's Resources? My project is a Windows Forms application in C#.

question from:https://stackoverflow.com/questions/4125698/how-to-play-wav-audio-file-from-resources

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Because mySoundFile is a Stream, you can take advantage of SoundPlayer's overloaded constructor, which accepts a Stream object:

System.IO.Stream str = Properties.Resources.mySoundFile;
System.Media.SoundPlayer snd = new System.Media.SoundPlayer(str);
snd.Play();

SoundPlayer Class Documentation (MSDN)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...