1
public partial class Form1 : Form
{
    SecondarySoundBuffer m_DSoundBuffer;
    DirectSound m_DirectSound;
    string fileName = @"F:\\guitar-classical-E-octave0.wav";
    public void setting()
    {
        WaveStream waveFile = new WaveStream(fileName);
        SoundBufferDescription desc = new SoundBufferDescription();
        desc.SizeInBytes = (int)waveFile.Length;
        desc.Flags = BufferFlags.None;
        desc.Format = waveFile.Format;
        m_DirectSound = new DirectSound();
        m_DirectSound.SetCooperativeLevel(this.Handle, CooperativeLevel.Priority);
        m_DSoundBuffer = new SecondarySoundBuffer(m_DirectSound, desc);
    }
    public Form1()
    {
        InitializeComponent(); 
    }
    private void button1_Click(object sender, EventArgs e)
    {
        setting();
        m_DSoundBuffer.Play(0, 0);
    }


}

我是 SlimDX 的第一人。

我正在尝试播放波形文件。但它不起作用!

也许有什么不对??

使用 WinForms、SlimDX.DirectSound、SlimDX.Mutimemedia

4

1 回答 1

0

我做的。

缓冲区必须写!!

public void setting()
    {
        m_DirectSound = new DirectSound();
        m_DirectSound.SetCooperativeLevel(this.Handle, CooperativeLevel.Priority);
        m_DirectSound.IsDefaultPool = false;

        using (WaveStream waveFile = new WaveStream(fileName))
        {

            SoundBufferDescription desc = new SoundBufferDescription();
            desc.SizeInBytes = (int)waveFile.Length;
            desc.Flags = BufferFlags.None;
            desc.Format = waveFile.Format;

            m_DSoundBuffer = new SecondarySoundBuffer(m_DirectSound, desc);
            byte[] data = new byte[desc.SizeInBytes];
            waveFile.Read(data, 0, (int)waveFile.Length);
            m_DSoundBuffer.Write(data, 0, LockFlags.None);
        }
于 2015-04-27T18:18:33.433 回答