我希望在窗体加载时播放声音。
SoundPlayer sound = new SoundPlayer( @"song.mp3" );
sound.Play();
当将此项目分发给他人时,无法使用绝对路径。在这种情况下,我该如何使用相对路径?其中
song.mp3
位于"C:\ Users \ xxx \ Desktop \ Game \ Resources \ song.mp3"
中?谢谢。
我希望在窗体加载时播放声音。
SoundPlayer sound = new SoundPlayer( @"song.mp3" );
sound.Play();
song.mp3
位于"C:\ Users \ xxx \ Desktop \ Game \ Resources \ song.mp3"
中?创建一个资源包并将其存储在bundle中,只需在bundle中引用声音文件即可。
例如:默认情况下,在创建WinForms项目时,您会在Properties文件夹中看到一个Resources.resx文件。在那里添加一个资源,然后从代码中引用它:
Properties.Resources.String1;