Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAudio WaveOut Device ID

Tags:

c#

.net

naudio

I need to select a WaveOut device to play sound, but I can't do that.

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

This function starts, then the form start. After this on my form, I select waveout device with combobox. Combobox is filled with this code:

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

After this, I select my device.

int WaveOutDeviceId = comboBox2.SelectedIndex;

And start Play function:

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

But my sound always play on default device (With number = 0). If I do this for microphone, this code works correctly.

like image 629
Alexander Mashin Avatar asked Nov 07 '25 19:11

Alexander Mashin


1 Answers

Once you've called Init it's too late to change DeviceId. I suggest creating a new instance of WaveOut when you want to change device.

like image 119
Mark Heath Avatar answered Nov 10 '25 10:11

Mark Heath



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!