我正在使用托管代码开发音乐播放器,并且正在使用 Microsoft.DirectX.DirectSound。当我调用 play 方法时,我收到此错误“值不在预期范围内”。因此,问题仅适用于 24 位 WAV 文件。这就是例外的原因。对于 16 位文件工作正常。任何想法如何使它也适用于 24 位文件?
谢谢!
using Microsoft.DirectX.DirectSound;
using DS = Microsoft.DirectX.DirectSound;
.......
private DS.Device sounddevice;
private DevicesCollection AuioDevList;
//Create buffer
private SecondaryBuffer secondaryBuffer;
private BufferDescription d = new BufferDescription();
private void initializeSound()
{
// List all Audio Cards
AuioDevList = new DevicesCollection();
// Populate cmbAudioCards
cmbAudioCards.Items.Clear();
for (int i = 0; i < AuioDevList.Count; i++)
{
cmbAudioCards.Items.Add(AuioDevList[i].Description);
}
cmbAudioCards.SelectedIndex = 0;
sounddevice = new DS.Device(AuioDevList[0].DriverGuid);
sounddevice.SetCooperativeLevel(this.Handle, CooperativeLevel.Normal);
// Set descriptor’s flags
d.ControlPan = true;
d.ControlVolume = true;
d.ControlFrequency = true;
d.ControlEffects = true;
}
private void prepareSound(string file)
{
playing = false;
//secondaryBuffer.Stop();
secondaryBuffer = new SecondaryBuffer(file, d, sounddevice);
secondaryBuffer.Volume = trkVolume.Value;
}
private void btnPlay_Click(object sender, EventArgs e)
{
//Here is throwing exception
secondaryBuffer.Play(0, BufferPlayFlags.Default);//
}