A simple class to play sound on netcf (part 2)
在实际测试中发现上一片文章(A simple class to play sound on netcf)中介绍的播放声音的类在pda中运行正常,但却无法在pc中工作,简单分析了一下原因,发现是dll的问题,pc和pda播放声音时用的dll不同。pc中是winmm,而pda中则是coredll,项目需要在pc和pda上都可以运行,因此加入了动态判断功能,识别程序运行在pc还是pda中,从而加载不同的dll来播放声音,下面对是该类的一个封装:
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace MiniCafe.Util
{
internal class NetHelpers
{
[Flags]
public enum PlaySoundFlags : int
{
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("winmm")]
public static extern bool PlaySound(string szSound, IntPtr hMod, PlaySoundFlags flags);
}
internal class NetCFHelpers
{
[Flags]
public enum PlaySoundFlags : int
{
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")]
public static extern bool PlaySound(string szSound, IntPtr hMod,PlaySoundFlags flags);
}
public class Sound
{
public static void Play(string strFileName)
{
if (Framework.IsNetCF)
{
//for pda
NetCFHelpers.PlaySound(strFileName, IntPtr.Zero,
NetCFHelpers.PlaySoundFlags.SND_FILENAME | NetCFHelpers.PlaySoundFlags.SND_ASYNC);
}
else
{
//for pc
NetHelpers.PlaySound(strFileName, IntPtr.Zero,
NetHelpers.PlaySoundFlags.SND_FILENAME | NetHelpers.PlaySoundFlags.SND_ASYNC);
}
}
}
}
转载于:https://www.cnblogs.com/swnuwangyun/archive/2006/11/10/556822.html
A simple class to play sound on netcf (part 2)相关推荐
- 为什么测试喜欢ie_为什么我现在喜欢测试,以及为什么您也应该如此。
为什么测试喜欢ie by Evelyn Chan 通过伊芙琳·陈 为什么我现在喜欢测试,以及为什么您也应该如此. (Why I now appreciate testing, and why you ...
- [翻译] SoundManager 音频管理器
SoundManager 音频管理器 https://github.com/nicklockwood/SoundManager Purpose SoundManager is a simple cla ...
- 博弈论 ai 大数据开源库_需要进化:博弈论与人工智能
博弈论 ai 大数据开源库 by Elena Nisioti 由Elena Nisioti 需要进化:博弈论与人工智能 (In need of evolution: game theory and A ...
- MessageBeep函数
这个函数用来发出系统声音. 函数原型如下: BOOL MessageBeep( UINT uType); 其中uType必须是以下中的一个 Value Meaning -1 Simple beep ...
- The Simple Life
The simple life, although hard to reach it in a big city- Quiet mornings. Sing-a-long songs with my ...
- java sound api_Java Sound API
Java Sound API是javaSE平台提供底层的(low-level)处理声音接口. 例外,java也提供了简单的实用的高层媒体接口(higher-level) - JMF(Java Medi ...
- H323plus的学习使用(2)——simple实现音视频通话
H323plus的学习使用(2)--simple实现音视频通话 但该文章的解释大多不够详细,而且使用的版本不同,编译安装的环境也不同,导致了文章中所说的解决方法并不能够十分完美地解决,本人在按照该文章 ...
- 简单句(Simple sentences)-one
简单句(simple sentences) 句子 主谓 英语句子必须具备主谓结构,并且主语是谓语动词地发出者,宾语是谓语动词地承受者 我的英语说的很好先找出谓语动词 说在找出主语 我宾语就是英语I s ...
- amixer: Unable to find simple control 'Master',0
为什么80%的码农都做不了架构师?>>> Python程序需要调用shell命令设置系统音量: amixer set Master 30% #音量设定为30% 在一台ubunt ...
最新文章
- [error] - Build path is incomplete. Cannot find class file for org/aspectj/weaver/refl
- java医疗框架,java毕业设计_springboot框架的城市智慧医疗服务系统
- redis存opc_Redis集群的三种模式
- matlab impdt,实验1 基于Matlab的数字信号处理基本操作
- MlLib--逻辑回归笔记
- webrtc 判断是否支持_5G时代-WebRTC音视频高级开发
- Java开发学习教程之对象的创建与使用
- 从“童话脸”到Avatarify,AI换脸究竟带来了什么?
- windows下安装linux环境
- python处理工资_python的工资
- 凑数算法 c语言,算法题解 - 牛客编程巅峰赛S1第4场 - 黄金钻石组
- 如何解决遇到的The server time zone value ‘?й???????‘ is unrecognized or represents more than one time zone
- kaggle 收不到手机验证码
- 基于GEC6818开发板的相册
- LEFT JOIN 与 RIGHT JOIN
- linux rpm安装包忽视所有依赖强制安装
- LCS、LIS及LCIS
- 让子盒子在父盒子中垂直居中的七个方法
- 维多利亚旅行者 V6004 时尚休闲商务双肩包 黑色[价格 行情 报价] - 易迅网
- Oracle 12 创建数据库