NAudio WaveOut 设备 ID

问题描述 投票:0回答:1

我需要选择一个

WaveOut
设备来播放声音,但我不能这样做。

void Initialize()
{
    _WaveOut = new WaveOut();
    var reader = new WaveFileReader(FileName);
    _WaveOut.Init(new WaveChannel32(reader));
}

该函数启动,然后表单启动。在我的表单上之后,我选择带有组合框的波形设备。组合框填充了以下代码:

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

此后,我选择我的设备。

int WaveOutDeviceId = comboBox2.SelectedIndex;

并启动播放功能:

void Play()
{
    _WaveOut.DeviceNumber = WaveOutDeviceId;
    _WaveOut.Play();
}

但我的声音总是在默认设备上播放(数字= 0)。如果我对麦克风执行此操作,则此代码可以正常工作。

c# .net naudio
1个回答
8
投票

一旦您致电

Init
,再更改就为时已晚
DeviceId
。我建议当您想要更改设备时创建一个新的
WaveOut
实例。

© www.soinside.com 2019 - 2024. All rights reserved.