我正在尝试使用以下方法加载和播放波形文件:
SoundPlayer simpleSound = new SoundPlayer(@"pack://application:,,,/MyAssembly;component/Sounds/10meters.wav");
simpleSound.Play();
没有成功。我得到一个System.NotSupportedException
:(见下文。
System.NotSupportedException: The URI prefix is not recognized.
at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
at System.Net.WebRequest.Create(Uri requestUri)
at System.Media.SoundPlayer.LoadSync()
at System.Media.SoundPlayer.LoadAndPlay(Int32 flags)
at System.Media.SoundPlayer.Play()
我查看了谷歌并试图找到解决方案,但没有任何效果。使用直接路径播放文件可以正常工作
SoundPlayer simpleSound = new SoundPlayer(@"D:\Projects\MyAssembly\Sounds\10meters.wav");
simpleSound.Play();
我还检查了 MyAssembly 的内容,资源在那里。不SoundPlayer
支持打包或有什么我做的不对?