C#使用HWQPlayer類播放wav文件類的代碼: 1 using System.IO; 2 using System.Runtime.InteropServices; 3 4 namespace HoverTreeSound.HewenqiFrame 5 { 6 internal class H
C#使用HWQPlayer類播放wav文件
類的代碼:
1 using System.IO; 2 using System.Runtime.InteropServices; 3 4 namespace HoverTreeSound.HewenqiFrame 5 { 6 internal class HWQPlayer 7 { 8 [DllImport("winmm.dll")] 9 private static extern int sndPlaySoundA(byte[] lpszSoundName, int uFlags); 10 11 private const int SND_MEMORY = 0x4; 12 private const int SND_ASYNC = 0x1; 13 byte[] StreamToBytes(Stream stream) 14 { 15 byte[] bytes = new byte[stream.Length]; 16 stream.Read(bytes, 0, bytes.Length); 17 // 設置當前流的位置為流的開始 by 何問起 18 stream.Seek(0, SeekOrigin.Begin); 19 return bytes; 20 } 21 22 public void PlayWav(Stream stream) 23 { 24 sndPlaySoundA(StreamToBytes(stream), SND_MEMORY); 25 } 26 } 27 }
調用代碼:
new HWQPlayer().PlayWav(Properties.Resources.hewenqi);
調用的地方需要引用命名空間:
using HoverTreeSound.HewenqiFrame;
示例下載:http://hovertree.com/h/bjaf/4aaa1b2s.htm
界面:
轉載自:http://hovertree.com/h/bjaf/jeg0ytf5.htm
更多文章:http://www.cnblogs.com/sosoft/p/kaifajishu.html