C# 尝试使用Microsoft.Xna.Framework将wma文件作为SoundEffect加载时发生InvalidOperationException

C# 尝试使用Microsoft.Xna.Framework将wma文件作为SoundEffect加载时发生InvalidOperationException,c#,audio,xna,windows-phone-8,soundeffect,C#,Audio,Xna,Windows Phone 8,Soundeffect,尝试将WMA文件(无DRM)作为音效加载时,出现无效操作异常。我的代码: public void LoadSound(String SoundFilePath, out SoundEffect Sound) { Sound = null; try { // Holds informations about a file stream. StreamResourceInfo Soun

尝试将WMA文件(无DRM)作为音效加载时,出现无效操作异常。我的代码:

    public void LoadSound(String SoundFilePath, out SoundEffect Sound)
    {

        Sound = null;

        try
        {
            // Holds informations about a file stream.
            StreamResourceInfo SoundFileInfo = App.GetResourceStream(new Uri(SoundFilePath, UriKind.Relative));

            // Create the SoundEffect from the Stream
            Sound = SoundEffect.FromStream(SoundFileInfo.Stream);
        }
        catch (NullReferenceException)
        {
            // Display an error message
            MessageBox.Show("Couldn't load sound " + SoundFilePath);
        }
    }
此行出现错误
Sound=SoundEffect.FromStream(SoundFileInfo.Stream)


不过,我可以毫无问题地加载WAV文件。我不喜欢将WMA文件转换为WAV,因为原始WMA文件大小仅为352KB,但当转换为WAV文件时,其大小增加到1788KB

不能在SoundEffects中使用wma或mp3声音。尝试这种效果很好的方法:

使用Microsoft.Xna.Framework.Media;
...
Song s=Song.FromUri(“声音名称”,新Uri(@“Resources/Alarms/Alarm01.wma”,UriKind.Relative));
MediaPlayer.Play(s);
另外,不要忘记参考Microsoft.Xna.Framework