// 获取WaveOut设备数量
int deviceCount = WaveOut.DeviceCount;
// 遍历每个设备,获取其DeviceNumber及相关信息
for (int deviceNumber = 0; deviceNumber < deviceCount; deviceNumber++)
{
var capabilities = WaveOut.GetCapabilities(deviceNumber);
list1.Add(capabilities);
}
capabilities的信息如下
{
"Channels": 2,
"SupportsPlaybackRateControl": true,
"ProductName": "耳机 (2- High Definition Audio De",
"NameGuid": "de13cce0-8304-4ee9-bace-4824214e3ea5",
"ProductGuid": "dc97ac9c-ddec-4d59-b650-3b8ba67bc2a1",
"ManufacturerGuid": "d5a47fa8-6d98-11d1-a21a-00a0c9223196"
}
private WaveOutEvent waveOut = new WaveOutEvent();
private AudioFileReader reader;
bool NeedStop = false;
public NAudioPlayer(int deviceNumber, string audioFilePath)
{
// 初始化WaveOutEvent
waveOut.DeviceNumber = deviceNumber;
// 使用AudioFileReader读取音频文件
reader = new AudioFileReader(audioFilePath);
// 设置播放停止时的事件处理
waveOut.PlaybackStopped += OnPlaybackStopped;
// 初始化播放器
waveOut.Init(reader);
}
不可使用
var list2 = new MMDeviceEnumerator().EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active);
获取设备的deviceNumber
标签:int,Naudio,waveOut,deviceNumber,AudioFileReader,声卡,WaveOut,使用,capabilities From: https://www.cnblogs.com/simadi/p/18218134