我正在尝试为SoundPlayer对象设置文件路径
如果我的主项目文件夹中有一个声音文件夹.我该如何发送
Soundplayer test = new Soundplayer("Sounds/Fireball.wav");
Run Code Online (Sandbox Code Playgroud)
文件相对于主项目的位置并不重要.重要的是声音文件在部署/调试时相对于应用程序的位置.如果它将具有与主.exe路径相同的相对路径,那么您可以使用以下内容.
var root = typeof(Program).Assembly.Location;
var soundPath = Path.Combine(root, @"sounds\Fireball.wav");
var test = new SoundPlayer(soundPath);
Run Code Online (Sandbox Code Playgroud)