公司的项目中有播放声音的需求,刚开始时使用.net的System.Media.SoundPlayer 这个类,测试没有问题,但到了客户大量使用时,发现有些声音播放不了。
没办法,改用windows提供的API来播放。
[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint ="PlaySound", SetLastError =true, CharSet = CharSet.Unicode, ThrowOnUnmappableChar = true)]
private static externbool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);
首先定义一个枚举:
[System.Flags]
public enum PlaySoundFlags : int
{
<