我使用Jetbrains骑手作为IDE并在C#中编码;当我试图编译SoundPlayer类时,我没有声音也没有默认声音。我的代码如下:
public static void Main(string[] args) {
const string introSongLocation =
@"/Users/niller/DragonBallZ_GameFolder/Sounds/introToGame.wav";
var sound = new System.Media.SoundPlayer(introSongLocation);
sound.Load();
sound.Play();
System.Console.WriteLine(sound.IsLoadCompleted);
System.Console.WriteLine(sound.SoundLocation);
System.Console.ReadLine();
}
Output to terminal:
true
/Users/niller/DragonBallZ_GameFolder/Sounds/introToGame.wav
正如您在下面的代码中所知,我正在检查声音是否已加载,但如果不是SoundPlayer.Play()方法则会播放默认声音,如in所述。
因此我问: 是不是为wav声音文件提供路径,然后加载它,还是我必须将wav文件放在我的解决方案文件夹中?到目前为止,似乎没有任何工作。
解: 我使用的是MacBook,而该库仅适用于Windows和Linux。