• C# 播放和暂停播放wav文件


    [DllImport("winmm.DLL",
                EntryPoint = "PlaySound",
                SetLastError = true,
                CharSet = CharSet.Unicode,
                ThrowOnUnmappableChar = true)]
            private static extern bool PlaySound(string szSound, System.IntPtr hMod,
                PlaySoundFlags flags);

            [System.Flags]
            public enum PlaySoundFlags : int
            {
                SND_SYNC = 0x0000, //同步播放声音,在播放完后PlaySound函数才返回
                SND_ASYNC = 0x0001, //用异步方式播放声音,PlaySound函数在开始播放后立即返回
                SND_NODEFAULT = 0x0002, //不播放缺省声音,若无此标志,则PlaySound在没找到声音时会播放缺省声音
                SND_LOOP = 0x0008, //重复播放声音,必须与SND_ASYNC标志一块使用
                SND_NOSTOP = 0x0010, //PlaySound不打断原来的声音播出并立即返回FALSE
                SND_NOWAIT = 0x00002000, //如果驱动程序正忙则函数就不播放声音并立即返回
                SND_FILENAME = 0x00020000, //pszSound参数指定了WAVE文件名
                SND_RESOURCE = 0x00040004 //pszSound参数是WAVE资源的标识符,这时要用到hmod参数
            }


    public void runSound()
            {


                PlaySound(
    @"E:\报警声音\ALARM1.WAV", IntPtr.Zero,
                    SND_ASYNC 
    | SND_FileNAME | SND_LOOP);
            }

    private void button1_Click(object sender, EventArgs e)
            {
                PlaySound(
    null, IntPtr.Zero, SND_ASYNC);
            }

            
    private void button2_Click(object sender, EventArgs e)
            {
                
    new Thread(new ThreadStart(runSound)).Start();
            }
  • 相关阅读:
    php中file_get_contents的图片乱码
    Lsh and Rsh (左移和右移)
    |=的含义
    Intercultural Communication Drama
    VS代码块快速折叠快捷键
    C++sqrt()函数与sqrtf()函数的区别
    C++中union和struct之间的区别
    泛型编程
    生成百度网盘目录文件
    字符串前L的含义
  • 原文地址:https://www.cnblogs.com/kenter/p/2129688.html
Copyright © 2020-2023  润新知