在基于控制台的程序中,我想在其末尾使用声音文件,我能够使它正常工作,但是当我发布项目并尝试将其发送给其他人时,我无法将其包含在内声音文件,我该怎么做?
In my console based program I am wanting to use a sound file at the end of it, I was able to get that to work however when I publish the project and try send it to others I can't get it to include the sound file, how would I accomplish this?
推荐答案
代码:
System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream s = a.GetManifestResourceStream("<assemblyname>.<wavfilename>.wav"); SoundPlayer player = new SoundPlayer(s); player.PlaySync();用程序集的名称替换< assemblyname> ,并用添加的WAV文件的名称替换< wavfilename> .
replacing <assemblyname> with the name of your assembly, and <wavfilename> with the name of the WAV file that you added.
对于我的测试代码,该行如下所示:
For my test code, that line looked like this:
System.IO.Stream s = a.GetManifestResourceStream("ConsoleApp3.tada.wav");因为我的程序集名称为"ConsoleApp3",而wav文件名为"tada.wav".
because my assembly name is "ConsoleApp3" and the wav file was called "tada.wav".
请注意,您还需要使用System.Media; 将添加到源代码文件.
Note you will also need to add a using System.Media; to the source code file.
更多推荐
添加声音文件进行构建,并找到路径?C#
发布评论