无法播放声音

时间:2015-08-26 08:57:25

标签: c# wpf

我每次调用时都会发出声音播放的方法:

public static void getInformationSound() 
{
        Uri uri = new Uri(@"pack://application:,,,/../Resources/Sounds/SF_Info.wav");
        StreamResourceInfo sri = Application.GetResourceStream(uri);
        SoundPlayer simpleSound = new SoundPlayer(sri.Stream);
        simpleSound.Play();
 }

但在SoundPlayer simpleSound = new SoundPlayer(sri.Stream);行上我收到此错误:

  

对象引用未设置为对象的实例。

这是我的文件夹资源:

enter image description here

也许我错了URI? Project -> Resources (Folder) -> Sounds (Folder) -> file...

1 个答案:

答案 0 :(得分:-1)

试试这个:

MediaPlayer mplayer = new MediaPlayer();
mplayer.Open(new Uri(@"../../Resources/Sounds/SF_Info.wav", UriKind.Relative));
mplayer.Play();
相关问题