前天买了块wince的控制板,询问厂家如何用C#在wince下如何播放声音,令人郁闷的是,几天过去了也没问出个结果。只好自己找资料,
现在贡献出来,希望能帮助其他的朋友少走弯路。
我介绍的方法适用WinCE6.0和以前的所有版本。
1.首先介绍如何播放*.wav, 这个方式微软提供了标准的播放类,但不适合播放大文件的*.wav, 只适合10MB以内的简单系统提示语音。
如下:
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace Dengfengsoft
{
public class Sound
{
private byte[] m_soundBytes;
private string m_fileName;
//
private enum Flags
{
SND_SYNC = 0x0000, /* play synchronously (default) */
SND_ASYNC = 0x0001, /* plaSmartHomey 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