Unity 中带有 NAudio WaveOut 的 PlatformNotSupportedException

PlatformNotSupportedException with NAudio WaveOut in Unity

我正在尝试在 Unity 项目中使用 NAudio 在辅助声卡上播放声音。 使用编辑器中的 Play 按钮成功,但不在可执行文件构建中

这是我得到的错误:

System.PlatformNotSupportedException: Operation is not supported on this platform.
          at System.Windows.Forms.Form..ctor () [0x00000] in <0b0c181c86c84da989ad80998d3a0a84>:0 
          at NAudio.Wave.WaveWindow.OnMdiChildActivate (System.EventArgs e) [0x00000] in <554b80148c284b99953f098db496ebd4>:0 
          at (wrapper remoting-invoke-with-check) NAudio.Wave.WaveWindow..ctor(NAudio.Wave.WaveInterop/WaveCallback)
          at NAudio.Wave.WaveCallbackInfo.Connect (NAudio.Wave.WaveInterop+WaveCallback callback) [0x00009] in <554b80148c284b99953f098db496ebd4>:0 
          at NAudio.Wave.WaveOut..ctor (NAudio.Wave.WaveCallbackInfo callbackInfo) [0x0004e] in <554b80148c284b99953f098db496ebd4>:0 
          at NAudio.Wave.WaveOut..ctor () [0x00014] in <554b80148c284b99953f098db496ebd4>:0 
          at MainVideoScript.playSound (System.Int32 deviceNumber) [0x0002e] in <0d2c0b09fee74d5099fd910768d58ea9>:0 

我运行正在 Windows 10Target platform=Windows 上,那么为什么该平台不支持我正在尝试做的事情?我能改变什么?

这是我正在尝试的代码 运行:

        string soundPath = System.IO.Path.Combine(Application.streamingAssetsPath, @"clic2.wav");
        waveReader = new NAudio.Wave.WaveFileReader(soundPath);

        var wave = new NAudio.Wave.WaveOut();
        wave.DeviceNumber = deviceNumber;
        wave.Init(waveReader);
        wave.Play();

我用的是2019.2.8f1

您需要确保 Api compatibility LevelEdit \ Project Settings \ Player

中是正确的