NAudio WaveOut设备ID

EXT*_*RAM 2 .net c# naudio

我需要选择waveout设备,播放声音.但我不能这样做.

void Initialize()
{
_WaveOut = new WaveOut();
var reader = new WaveFileReader(FileName);
_WaveOut.Init(new WaveChannel32(reader));
}
Run Code Online (Sandbox Code Playgroud)

此函数启动,然后表单开始.在我的表单上,我选择带有组合框的waveout设备.Combobox是这段代码:

for (int i = 0; i < WaveOut.DeviceCount; i++)
{
     WaveOutCapabilities WOC = WaveOut.GetCapabilities(i);
     comboBox2.Items.Add(WOC.ProductName);

}
Run Code Online (Sandbox Code Playgroud)

在此之后,我选择了我的设备.

int WaveOutDeviceId = comboBox2.SelectedIndex;
Run Code Online (Sandbox Code Playgroud)

并启动Play功能:

void Play()
{
_WaveOut.DeviceNumber = WaveOutDeviceId;
_WaveOut.Play();
}
Run Code Online (Sandbox Code Playgroud)

但我的声音总是在默认设备上播放(数字= 0).如果我这样做麦克风,这段代码可以正常工作.

Mar*_*ath 5

一旦你打电话Init就太晚了,无法改变DeviceId.我建议WaveOut您在想要更改设备时创建一个新实例.