右键音乐文件Sound1.wav属性,生成属性改成 嵌入的资源

解决方案 »

  1.   

    加上new Uri看一下:SoundPlayer player1 = new SoundPlayer(new Uri(s2));
      

  2.   

    SoundPlayer 没有参数是URI的构造函数
      

  3.   

    参考: 
    URI Prefix not supported
    How can the MediaElement play WAV file that is part of a Resourcefile?Uri uri = new Uri(@"pack://application:,,,/MyAssembly;component/Sounds/10meters.wav");
    StreamResourceInfo sri = Application.GetResourceStream(uri);
    SoundPlayer simpleSound = new SoundPlayer(sri.Stream);
    simpleSound.Play();
    SoundPlayer 没有参数是URI的构造函数
      

  4.   


        string s2 = "pack://application:,,,/aa/Sound1.wav";
        SoundPlayer player1 = new SoundPlayer(s2);
        player1.Play();//或者用绝对路径
                SoundPlayer player = new SoundPlayer();
                string location = Environment.CurrentDirectory + "\\aa\\Sound1.wav"; 
                player.SoundLocation = location; 
                player.Play();