sound.cs

来自「本人觉得C#的软件是不需要源代码的」· CS 代码 · 共 58 行

CS
58
字号
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace SmartAnswerCall
{


    public class Sound
    {
        private string m_fileName;
        private byte[] m_soundBytes;

        public Sound(Stream stream)
        {
            this.m_soundBytes = new byte[stream.Length];
            stream.Read(this.m_soundBytes, 0, (int)stream.Length);
        }

        public Sound(string fileName)
        {
            this.m_fileName = fileName;
        }

        public void Play()
        {
            if (this.m_fileName != null)
            {
                WCE_PlaySound(this.m_fileName, IntPtr.Zero, 0x20001);
            }
            else
            {
                WCE_PlaySoundBytes(this.m_soundBytes, IntPtr.Zero, 5);
            }
        }

        [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private static extern int WCE_PlaySound(string szSound, IntPtr hMod, int flags);
        [DllImport("CoreDll.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private static extern int WCE_PlaySoundBytes(byte[] szSound, IntPtr hMod, int flags);

        private enum Flags
        {
            SND_ALIAS = 0x10000,
            SND_ALIAS_ID = 0x110000,
            SND_ASYNC = 1,
            SND_FILENAME = 0x20000,
            SND_LOOP = 8,
            SND_MEMORY = 4,
            SND_NODEFAULT = 2,
            SND_NOSTOP = 0x10,
            SND_NOWAIT = 0x2000,
            SND_RESOURCE = 0x40004,
            SND_SYNC = 0
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?