C#播放wav文件
2016-02-15 09:26
477 查看
C#使用HWQPlayer类播放wav文件
类的代码:
调用代码:
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
类的代码:
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
相关文章推荐
- 《你不常用的c#之二》:略谈GCHandle
- 基于C#实现手机号码归属地接口调用
- C# Datatable排序
- C# 文件下载四方法
- C#索引器
- C#中的增删改查
- 【C#】基础实例演练
- C#学习——对象和类
- C#遍历文件夹,只需一句话
- C#八数码游戏实例
- C#向其它电脑共享文件夹上传及下载文件
- Visual Studio 2008 可扩展性开发(八):关于用户界面的种种(下)
- Visual Studio 2008 可扩展性开发(八):关于用户界面的种种(上)
- Visual Studio 2008 可扩展性开发(六):操作Solution Explorer
- Visual Studio 2008 可扩展性开发(五):操作Solution、Project和ProjectItem
- Visual Studio 2008 可扩展性开发(四):添加新的命令
- c#正则表达式详解
- Visual Studio 2008 可扩展性开发(三):Add-In运行机制解析(下)
- Visual Studio 2008 可扩展性开发(三):Add-In运行机制解析(上)
- Visual Studio 2008 可扩展性开发(二):Macro和Add-In初探