C#控制声卡播放声音
using Microsoft.DirectX.DirectSound;
public partial class Form1 : Form
{
private DevicesCollection myDevices = null;
private struct myDeviceDescription
{
public DeviceInformation info;
public override string ToString()
{
return info.Description;
}
public myDeviceDescription(DeviceInformation di)
{
info = di;
}
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
myDevices = new DevicesCollection();
Guid driverGuid = Guid.Empty;
foreach (DeviceInformation deviceInfo in myDevices)
{
if (!string.IsNullOrEmpty(deviceInfo.ModuleName))
{
driverGuid = deviceInfo.DriverGuid;
break;
}
}
Device dv = new Device(driverGuid);
dv.SetCooperativeLevel(this, CooperativeLevel.Normal);
SecondaryBuffer buf = new SecondaryBuffer("nopayhint.wav", dv);
buf.Play(0, BufferPlayFlags.Default);
}
}