我是
System.Media
的新手,我想简单地使用 .wav
播放 c#
文件的声音 我完全按照这个问题的答案中所写的操作](How to play a sound in C#, .NET )并且它不会工作。
我使用了专门用于测试的特殊 .wav
文件,因此这不会是问题。 file path
也不是问题,因为我复制了它而不是手动输入它。
我不知道我做错了什么,没有错误。 先感谢您!
这是代码
// using System.Media;
const string soundLocation = @"cannot share the actual path but its not the problem anyway";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundLocation);
player.Play();
我认为最好在 C# 中添加 wav 文件作为资源。完成后,您可以执行以下操作
使用系统.媒体;
System.Media.SoundPlayer Song1 = new System.Media.SoundPlayer(Properties.Resources.MoreThanEverything); //MorThanEverything 是 wav 文件的资源名称 。 。 歌曲1.Play();
我已将您的波形文件放入我的本地驱动器 (D:) 并尝试使用 .NET Framework 3.0 直到 .NET Framework 4.5 他们都播放声音。这是我的代码或你的代码;)
const string soundLocation = @"D:\\file_example_WAV_1MG.wav";
System.Media.SoundPlayer player = new System.Media.SoundPlayer(soundLocation);
player.Play();