C#播放wav文件

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值