How to play WAV audio file from Resources?

后端 未结 7 2136
面向向阳花
面向向阳花 2020-12-02 10:10

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

7条回答
  •  我在风中等你
    2020-12-02 10:22

    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)

提交回复
热议问题