110,533
社区成员
发帖
与我相关
我的任务
分享
[DllImport("winmm.dll")]
public static extern bool PlaySound(string pszSound,int hmod,int fdwSound);
public const int SND_FILENAME = 0x00020000;
public const int SND_ASYNC = 0x0001;
PlaySound("提示时奏幻想空间.WAV",0,SND_ASYNC|SND_FILENAME);
using System;
using System.Runtime.InteropServices;
using System.ComponentModel;
public class clsPlaySound
{
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;
[DllImport("Winmm.dll", CharSet=CharSet.Auto)]
protected extern static bool PlaySound(string strFile, IntPtr hMod, int flag );
//播放声音函数
//strSoundFile --- 声音文件
//bSynch --- 是否同步,如果为True,则播放声音完毕再执行后面的操作,为False,则播放声音的同时继续执行后面的操作
public static bool PlaySoundFile(string strSoundFile, bool bSynch)
{
if(!System.IO.File.Exists(strSoundFile))
return false;
int Flags;
if(bSynch)
Flags = SND_FILENAME | SND_SYNC;
else
Flags = SND_FILENAME | SND_ASYNC;
return PlaySound(strSoundFile, IntPtr.Zero, Flags);
}
}
//连续播放时
for each(string file in files)
{
clsPlaySound.PlaySoundFile(file,true);
}