我试图加载和使用播放波形文件:URI前缀不支持
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()
我看了看谷歌和SO试图找到一个解决方案,毫无效果。 播放该文件有直接路径工作正常
SoundPlayer simpleSound = new SoundPlayer(@"D:\Projects\MyAssembly\Sounds\10meters.wav");
simpleSound.Play();
我也检查内容MyAssembly的,资源是存在的。 是否SoundPlayer
不支持包装或有什么我不这样做是否正确?
好的C所有的流构造函数。 –
+1谢谢。 'StreamResourceInfo sri = Application.GetResourceStream(uri);'没有工作,因为我是从一个dll文件而不是主要的exe应用程序执行此操作。 MediaPlayer对我所做的事情来说太重了:(其他的想法是什么? – GETah
你是什么意思,“没有用”?你只需要添加一个对PresentationFramework的引用就可以了。 WPF,如果这就是你想要做的... –