using System; using System.Runtime.InteropServices; using System.IO; namespace DeviceApplication { /// /// Sound 的摘要说明。 /// string filename = Path.GetDirectoryName(Assembly.GetExecutingAssembly() /// .GetName().CodeBase) + @"/aa.wav"; /// 调用方法:Sound sound = new Sound(filename); /// 开始播放 sound.Play(); 停止播放 sound.endPlay(); public class Sound { private byte[] m_soundBytes; private string m_fileName; private enum Flags { SND_SYNC = 0x0000, /* play synchronously (default) */ SND_ASYNC = 0x0001, /* play asynchronously */ SND_NODEFAULT = 0x0002, /* silence (!default) if sound not found */ SND_MEMORY = 0x0004, /* pszSound points to a memory file */ SND_LOOP = 0x0008, /* loop the sound until next sndPlaySound */ SND_NOSTOP = 0x0010, /* don't stop any currently playing sound */ SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */ SND_ALIAS = 0x00010000, /* name is a registry alias */ SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */ SND_FILENAME = 0x00020000, /* name is file name */ SND_RESOURCE = 0x00040004 /* name is resource name or atom */ } [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)] private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags); [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)] private extern static int WCE_PlaySoundBytes(byte[] szSound, IntPtr hMod, int flags); [DllImport("CoreDll.DLL", EntryPoint = "PlaySoundW", SetLastError = true)] private extern static int PlaySoundW(string szSound, int hMod, int flags); [DllImport("CoreDll.DLL", CharSet = CharSet.Auto)] public extern static bool sndPlaySound(string lpszSoundname, uint fuSound); [DllImport("coredll")] public static extern bool PlaySound(string szSound, IntPtr hMod, int flags); public Sound(string fileName) { m_fileName = fileName; } public Sound(Stream stream) { // read the data from the stream m_soundBytes = new byte[stream.Length]; stream.Read(m_soundBytes, 0, (int)stream.Length); } /// <summary> /// 持续播放 /// </summary> public void Play() { // if a file name has been registered, call WCE_PlaySound, // otherwise call WCE_PlaySoundBytes if (m_fileName != null) WCE_PlaySound(m_fileName, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME | Flags.SND_LOOP)); else WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_MEMORY | Flags.SND_LOOP)); } /// <summary> /// 播放一次 /// </summary> public void PlayOnce() { // if a file name has been registered, call WCE_PlaySound, // otherwise call WCE_PlaySoundBytes if (m_fileName != null) WCE_PlaySound(m_fileName, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME | Flags.SND_NOWAIT)); else WCE_PlaySoundBytes(m_soundBytes, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_MEMORY)); } /// <summary> /// 停止播放 /// </summary> public void EndPlay() { try { WCE_PlaySoundBytes(null, IntPtr.Zero, (int)(Flags.SND_SYNC | Flags.SND_MEMORY | Flags.SND_NOWAIT)); } catch (Exception e) { string str; str = e.Message; } } } }
您还没有登录,请您登录后再发表评论
NET CF 开发技巧1,针对.NET CF开发的技巧。
net cf 1.0写的一个GIF播放控件
Sandisk cf卡专用工具修改HD模式,解决无法分区的问题,部分新卡不保证有效,注意软件只支持firmware revision已H开头的卡 sandisk公开提供ATCFWCHG.COM程序 具体如下: 将CF卡通过硬盘盒在电脑上建立分区并格式...
封包封包封包CF2.7封包CF2.7封包CF2.7封包
cfmmc.cer这是个登陆cfmmc.com的证书,需在jdk中导下
CF窗口化CF源码
\CF_IDE_Exemple\uCOSII_FAT_CF 演示程序所在文件夹 \CF_IDE_Exemple\uCOSII_FAT_CF\arm uC/OS-II ARM7 LPC22xx移植代码 \CF_IDE_Exemple\uCOSII_FAT_CF\SOURCE uC/OS-II V2.52源代码(由于版权原因我们不能...
CF一键搜索基址 易语言源码 绝对无毒
CF窗口化源码(可调节大小).e 把CF弄成窗口化你懂得
easyImageWIN CF卡备份软件
仿CF官网网站源码
cf自动开枪源码
CF卡接口定义,介绍CF卡各接口的功能和作用,便于了解CF卡的功能
刷CF点软件CF解封器源码
在网上找了半天,没有这个东东。只好下了源代码自己编译。 现在传上来,方便大家
一个高防CF登录窗口的易语言源码 高防高防!
Siemens CF卡授权找回方法, 当SIMOTION或S120的CF卡授权不慎丢失的时候,可以通过此方法找回。
请注意:此款软件仅适合手里有佑华CF-B1211 CF卡拷贝机的下载使用,软件名称为Get ID,可将CF卡序列号、名称、版本号、容量信息,以TXT文档形式保存到本地电脑上,如过手里没有拷贝机的,下载使用无法使用的。
.net cf发送短信类的源代码,支持.net cf 1.0以上
《CF辅助易语言源码》 叫你怎样自作CF辅助易语言源码
相关推荐
NET CF 开发技巧1,针对.NET CF开发的技巧。
net cf 1.0写的一个GIF播放控件
Sandisk cf卡专用工具修改HD模式,解决无法分区的问题,部分新卡不保证有效,注意软件只支持firmware revision已H开头的卡 sandisk公开提供ATCFWCHG.COM程序 具体如下: 将CF卡通过硬盘盒在电脑上建立分区并格式...
封包封包封包CF2.7封包CF2.7封包CF2.7封包
cfmmc.cer这是个登陆cfmmc.com的证书,需在jdk中导下
CF窗口化CF源码
\CF_IDE_Exemple\uCOSII_FAT_CF 演示程序所在文件夹 \CF_IDE_Exemple\uCOSII_FAT_CF\arm uC/OS-II ARM7 LPC22xx移植代码 \CF_IDE_Exemple\uCOSII_FAT_CF\SOURCE uC/OS-II V2.52源代码(由于版权原因我们不能...
CF一键搜索基址 易语言源码 绝对无毒
CF窗口化源码(可调节大小).e 把CF弄成窗口化你懂得
easyImageWIN CF卡备份软件
仿CF官网网站源码
cf自动开枪源码
CF卡接口定义,介绍CF卡各接口的功能和作用,便于了解CF卡的功能
刷CF点软件CF解封器源码
在网上找了半天,没有这个东东。只好下了源代码自己编译。 现在传上来,方便大家
一个高防CF登录窗口的易语言源码 高防高防!
Siemens CF卡授权找回方法, 当SIMOTION或S120的CF卡授权不慎丢失的时候,可以通过此方法找回。
请注意:此款软件仅适合手里有佑华CF-B1211 CF卡拷贝机的下载使用,软件名称为Get ID,可将CF卡序列号、名称、版本号、容量信息,以TXT文档形式保存到本地电脑上,如过手里没有拷贝机的,下载使用无法使用的。
.net cf发送短信类的源代码,支持.net cf 1.0以上
《CF辅助易语言源码》 叫你怎样自作CF辅助易语言源码