首页 > 解决方案 > Unity 中带有 NAudio WaveOut 的 PlatformNotSupportedException

问题描述

我正在尝试NAudioUnity项目中使用的辅助声卡上播放声音。 它可以使用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

标签: c#unity3dnaudio

解决方案


您需要确保\ \Api compatibility Level中的正确EditProject SettingsPlayer

在此处输入图像描述


推荐阅读