c# 播放声音文件解决办法
c# 播放声音文件
在设能设备里面播放声音文件,执行过程对的时候提示一种声音,错误执行另外一种声音
本来用的是 DecodeAssembly,但在 window CE的设备里面会提示---无法找到 PInvoke DLL“Decoder.dll”。
//创建变量
DecodeAssembly decodeassembly = new DecodeAssembly();这个时候会提示错误
请会的帮忙解决下,谢谢
------解决方案--------------------
调用播放声音
CommonLib.clsPlaySound.PlaySoundFile("c:\\windows\\a.wav",false);
在设能设备里面播放声音文件,执行过程对的时候提示一种声音,错误执行另外一种声音
本来用的是 DecodeAssembly,但在 window CE的设备里面会提示---无法找到 PInvoke DLL“Decoder.dll”。
//创建变量
DecodeAssembly decodeassembly = new DecodeAssembly();这个时候会提示错误
请会的帮忙解决下,谢谢
c#
dll
------解决方案--------------------
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace CommonLib
{
/// <summary>
/// clsPlaySound 的摘要说明。
/// </summary>
public class clsPlaySound
{
protected const int SND_SYNC = 0x0;
protected const int SND_ASYNC = 0x1;
protected const int SND_NODEFAULT = 0x2;
protected const int SND_MEMORY = 0x4;
protected const int SND_LOOP = 0x8;
protected const int SND_NOSTOP = 0x10;
protected const int SND_NOWAIT = 0x2000;
protected const int SND_ALIAS = 0x10000;
protected const int SND_ALIAS_ID = 0x110000;
protected const int SND_FILENAME = 0x20000;
protected const int SND_RESOURCE = 0x40004;
protected const int SND_PURGE = 0x40;
protected const int SND_APPLICATION = 0x80;
[DllImport("Winmm.dll", CharSet=CharSet.Auto)]
protected extern static bool PlaySound(string strFile, IntPtr hMod, int flag );
//播放声音函数
//strSoundFile --- 声音文件
//bSynch --- 是否同步,如果为True,则播放声音完毕再执行后面的操作,为False,则播放声音的同时继续执行后面的操作
public static bool PlaySoundFile(string strSoundFile, bool bSynch)
{
if(!System.IO.File.Exists(strSoundFile))
return false;
int Flags;
if(bSynch)
Flags = SND_FILENAME
------解决方案--------------------
SND_SYNC;
else
Flags = SND_FILENAME
------解决方案--------------------
SND_ASYNC;
return PlaySound(strSoundFile, IntPtr.Zero, Flags);
}
}
}
调用播放声音
CommonLib.clsPlaySound.PlaySoundFile("c:\\windows\\a.wav",false);