C#播放wave提示音的类
来源:互联网 发布:淘宝网商品怎么分期购 编辑:程序博客网 时间:2024/05/19 05:03
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication7
{
public class WPlaySound
{
[DllImport("winmm.dll", EntryPoint = "PlaySound", CharSet = CharSet.Auto)]
private static extern int PlaySound(String pszSound, int hmod, int falgs);
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;
/// <summary>
///
/// </summary>
public WPlaySound()
{
}
/// <summary>
/// Plays specified wav file.
/// </summary>
/// <param name="pszSound"></param>
/// <returns></returns>
public static void PlaySound(String pszSound)
{
// Play asynchronously
// Asynchronously = 0x0001,
// Name is file name
// Filename = 0x00020000,
if (File.Exists(pszSound))
{
PlaySound(pszSound, 0, SND_ASYNC | SND_FILENAME | SND_LOOP);
}
}
public static void StopSound()
{
PlaySound(null, 0, SND_FILENAME);
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication7
{
public class WPlaySound
{
[DllImport("winmm.dll", EntryPoint = "PlaySound", CharSet = CharSet.Auto)]
private static extern int PlaySound(String pszSound, int hmod, int falgs);
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;
/// <summary>
///
/// </summary>
public WPlaySound()
{
}
/// <summary>
/// Plays specified wav file.
/// </summary>
/// <param name="pszSound"></param>
/// <returns></returns>
public static void PlaySound(String pszSound)
{
// Play asynchronously
// Asynchronously = 0x0001,
// Name is file name
// Filename = 0x00020000,
if (File.Exists(pszSound))
{
PlaySound(pszSound, 0, SND_ASYNC | SND_FILENAME | SND_LOOP);
}
}
public static void StopSound()
{
PlaySound(null, 0, SND_FILENAME);
}
}
}
可以直接调用函数,而不需要实例化对象。
0 0
- C#播放wave提示音的类
- 播放Wave的缓冲区《一》
- .Net下C#播放WAV,WAVE文件
- WAVE播放
- 简单记录,非常简单的一个提示音播放类(允许多个提示音播放)
- VB实现远程读取音频(Wave格式)的播放时间
- 简单的用 Microsoft.DirectX.DirectSound播放wave音频文件
- PyAudio——播放wave文件的实例
- 播放短促提示音的最佳办法
- C#播放MP3的类
- C#播放MP3的类
- C#播放MP3的类
- C#播放MP3的类
- C#播放MP3的类
- android播放提示音工具类(SoundConfigUtils)
- java播放提示音
- html播放提示音
- android 播放提示音
- Bash Shell 递归实现目录中文件拷贝
- 【IOS编程 02】加法器
- WCF入门(五)——单向通知
- Android GPS技术之LocationManager
- 手斧Linux – 从LFS到Funtoo (5)
- C#播放wave提示音的类
- 【DP】HDU-3008 Warcraft
- python 网络发送接收数据代码
- 二叉树面试题
- Tarjan算法求LCA(最近公共祖先)
- 手斧Linux – 从LFS到Funtoo (6)
- HTML5学习之路(一)-强大的HTML5
- Spring IoC使用的基本配置
- 手斧Linux – 从LFS到Funtoo (7)