-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Console app - Issue to get the list of devices #1204
Comments
@AlbertoVPersonal use WASAPI. It is the "new" way for audio playpack and recording. |
@rdyhalt I tested that version but the loopback did not run well. Possibly I had some wrong code. Thanks for advance! |
You app will start playback. But you use Thread.Sleep on the main thread. That does not work as expected. Try Google some code examples for NAudio. |
namespace ConsoleAppAudioDevices
{
using NAudio.CoreAudioApi;
using NAudio.Wave;
internal class Program
{
internal static async Task Main(string[] args)
{
const string AUDIO_PATH = "sounds/my_sound.wav";
using var enumerator = new MMDeviceEnumerator();
var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
var devices = enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)
.Where(x => x.ID != defaultDevice.ID).Prepend(defaultDevice);
foreach (var device in devices)
{
using var player = new WasapiOut(device, AudioClientShareMode.Shared, false, 0);
var tcs = new TaskCompletionSource();
await using var audioFile = new AudioFileReader(AUDIO_PATH);
player.Init(audioFile);
player.Play();
player.PlaybackStopped += (_, _) => tcs.SetResult();
await tcs.Task;
}
}
}
} Also for your initial problem, you can change <TargetFramework>net8.0</TargetFramework> to <TargetFramework>net8.0-windows</TargetFramework> |
Hi @JustArion, I have had to update the code to the following (see below). using var enumerator2 = new MMDeviceEnumerator();
var defaultDevice = enumerator2.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
var devices2 = enumerator2.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)
.Where(x => x.ID != defaultDevice.ID).Prepend(defaultDevice);
int i = 0;
var tcs = new TaskCompletionSource<int>(); // defined a return type
foreach (var device in devices2)
{
while (i <= 5)
{
// your code
// using var player = new WasapiOut(device, AudioClientShareMode.Shared, false, 0);
// my version
using var player = new WasapiOut(device, AudioClientShareMode.Shared, true, 200);
await using var audioFile = new AudioFileReader(AUDIO_PATH);
player.Init(audioFile);
player.Play();
while (player.PlaybackState == PlaybackState.Playing) ; // added
//player.PlaybackStopped += (_, _) => tcs.SetResult(25);
++i;
}
if (!tcs.Task.IsCompleted)
{
tcs.SetResult(25);
}
}
return await tcs.Task; Thanks for advance. |
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
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
Thanks for advance,
Alberto
The text was updated successfully, but these errors were encountered: