Skip to content

Console app - Issue to get the list of devices #1204

Open
@AlbertoVPersonal

Description

Hi all,

Description

I would like to get the list of devices but there is a class that does not exist and I don't know why.

Enviroment

  • app type: console
  • .NET version: 8.0
  • NAudio library version: 2.2.1

Steps to reproduce

Create a sample console app with the code (see below).

Current issue

WaveOut does not exist in the current context.

Expected behaviour

Not applicable

Other alternatives

Using the WASAPI enumerator, I get the list of devices. But the device number is not the same to the WaveOutEvent class.

Source code sample

using NAudio.Wave;

namespace ConsoleAppAudioDevices
{
    internal class Program
    {
        static void Main(string[] args)
        {
            const string AUDIO_PATH = "sounds/my_sound.wav";

            #region USE WAVE OUT

            for (int n = -1; n < WaveOut.DeviceCount; n++)
            {
                var caps = WaveOut.GetCapabilities(n);
                Console.WriteLine($"{n}: {caps.ProductName}");

                using (var audioFile = new AudioFileReader(AUDIO_PATH))
                using (var outputDevice = new WaveOutEvent())
                {
                    outputDevice.DeviceNumber = n;
                    outputDevice.Init(audioFile);
                    outputDevice.Play();
                    while (outputDevice.PlaybackState == PlaybackState.Playing)
                    {
                        Thread.Sleep(100);
                    }
                }

                Thread.Sleep(500);
            }

            #endregion

        }
    }
}

Thanks for advance,
Alberto

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions