Search code examples
naudionaudio-framework

Output audio to speaker and headset at the same time?


I'm using NAudio to output audio files to both the speaker and a headset on a window 10 laptop. I created two WaveOut and assigned the corresponding device number. But I cannot here the audio from the speaker when the headset is plugged in. Can anyone let me know how to solve this? Here's my code (it works fine on the headset or the speaker separately, but I want to hear the sound from both of them at the same time):

        var input1 = new Mp3FileReader(PATH + "left.mp3");
        var input2 = new Mp3FileReader(PATH + "right.mp3");
        var waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { input1, input2 }, 2);

        var input3 = new Mp3FileReader(PATH + "left.mp3");

        int channel = ((Mp3FileReader)input1).Mp3WaveFormat.Channels;
        Debug.WriteLine(channel);

        waveProvider.ConnectInputToOutput(0, 0);
        waveProvider.ConnectInputToOutput(3, 1);

        WaveOut wave = new WaveOut();
        wave.DeviceNumber = 1;
        wave.Init(waveProvider);

        WaveOut wave1 = new WaveOut();
        wave1.DeviceNumber = 0;
        wave1.Init(input3);

        wave.Play();
        wave1.Play();

Solution

  • I think the issue is that you don't have two soundcards, you have one soundcard that is switching between playing sound out of the speakers and headphones. If you bought a USB headset then you'd have two soundcards, and should be able to play different sounds through each one separately.