There are different soundout-providers which can play a sound. The two main soundout-providers are:

  1. DirectSoundOut
  2. WasapiOut

Choosing a device using DirectSound

The following code shows, how to enumerate all available devices:

public IEnumerable<DirectSoundDevice> EnumerateDirectSoundDevices()
{
    return new DirectSoundDeviceEnumerator().Devices;
}

Use the following code to set the device for a directsound playback:

public void ChooseADeviceUsingDirectSound()
{
    DirectSoundDevice anyDevice = EnumerateDirectSoundDevices().First();

    using(DirectSoundOut soundOut = new DirectSoundOut())
    {
        soundOut.Device = anyDevice.Guid;

        soundOut.Initialize(...)
    }
}

Note that after changing the Device-property, the Initialize-method has to be called. Changing the Device during a playback is not supported.

Choosing a device using Wasapi

Again, the following code shows, how to enumerate all available devices:

public IEnumerable<MMDevice> EnumerateWasapiDevices()
{
    using(MMDeviceEnumerator enumerator = new MMDeviceEnumerator())
    {
        return enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active);
    }
}

Last edited Apr 21, 2014 at 9:28 PM by filoe, version 2

Comments

No comments yet.