您的位置:首页 > 编程语言 > C#

C#播放wav文件

2016-02-15 09:26 477 查看
C#使用HWQPlayer类播放wav文件

类的代码:

using System.IO;
using System.Runtime.InteropServices;

namespace HoverTreeSound.HewenqiFrame
{
internal class HWQPlayer
{
[DllImport("winmm.dll")]
private static extern int sndPlaySoundA(byte[] lpszSoundName, int uFlags);

private const int SND_MEMORY = 0x4;
private const int SND_ASYNC = 0x1;
byte[] StreamToBytes(Stream stream)
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
// 设置当前流的位置为流的开始 by 何问起
stream.Seek(0, SeekOrigin.Begin);
return bytes;
}

public void PlayWav(Stream stream)
{
sndPlaySoundA(StreamToBytes(stream), SND_MEMORY);
}
}
}


调用代码:
new HWQPlayer().PlayWav(Properties.Resources.hewenqi);

调用的地方需要引用命名空间:
using HoverTreeSound.HewenqiFrame;

示例下载:http://hovertree.com/h/bjaf/4aaa1b2s.htm

界面:




转载自:http://hovertree.com/h/bjaf/jeg0ytf5.htm

更多文章:/article/4928709.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: