C # play wav files,
C # Use the HWQPlayer class to play wav files
Class Code:
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 // set the current stream position to the start of the 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}
Call code:
New HWQPlayer (). PlayWav (Properties. Resources. hewenqi );
The namespace must be referenced in the called place:
Using HoverTreeSound. HewenqiFrame;
Example download: http://hovertree.com/h/bjaf/4aaa1b2s.htm
Interface:
Reprinted from: http://hovertree.com/h/bjaf/jeg0ytf5.htm
More articles: http://www.cnblogs.com/sosoft/p/kaifajishu.html