sndPlaySound API 函数可以播放内存数据.

解决方案 »

  1.   


    private void Form1_Load(object sender, System.EventArgs e)
    {
    System.IO.FileStream inFile ;
    Byte[] binaryData; inFile = new System.IO.FileStream(@"C:\test.wav", 
    System.IO.FileMode.Open, 
    System.IO.FileAccess.Read);
    binaryData=new byte[inFile.Length]; inFile.Read(binaryData, 0, (int)inFile.Length);
    inFile.Close();
    //播放内存数据
    sndPlaySoundA(binaryData, SND_ASYNC | SND_NODEFAULT | SND_MEMORY); }
        [System.Runtime.InteropServices.DllImport("WINMM.DLL")] 
        private extern static int sndPlaySoundA(Byte[] lpszSoundName ,  int uFlags );    const int SND_ASYNC = 0x1;     // 异步播放
        const int SND_NODEFAULT = 0x2; // 不使用缺省声音
        const int SND_MEMORY = 0x4;    // lpszSoundName 指向一个内存文件