C # play wav files,

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.