public enum PlaySoundFlags : int {
SND_SYNC = 0x0, // play synchronously (default)
SND_ASYNC = 0x1, // play asynchronously
SND_NODEFAULT = 0x2, // silence (!default) if sound not found
SND_MEMORY = 0x4, // pszSound points to a memory file
SND_LOOP = 0x8, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x10, // don't stop any currently playing sound
SND_NOWAIT = 0x2000, // don't wait if the driver is busy
SND_ALIAS = 0x10000, // name is a registry alias
SND_ALIAS_ID = 0x110000,// alias is a predefined ID
SND_FILENAME = 0x20000, // name is file name
SND_RESOURCE = 0x40004, // name is resource name or atom
}; public class Sound
{
[DllImport("winmm.dll", SetLastError=true)]
public static extern bool PlaySound(string pszSound,System.IntPtr hmod,PlaySoundFlags flags); public static void Beep() {
Play("文件路径");
} public static void Play(string fileName) {
try {
PlaySound(fileName, IntPtr.Zero, (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC));
} catch (Exception ex) {
MessageBox.Show("Can't play sound file. " + ex.ToString());
}
}
}这是我从论坛上查到的编码,但在窗体程序中不播放音乐,只“笃“的一声响,请高手指点一下,谢谢!
SND_SYNC = 0x0, // play synchronously (default)
SND_ASYNC = 0x1, // play asynchronously
SND_NODEFAULT = 0x2, // silence (!default) if sound not found
SND_MEMORY = 0x4, // pszSound points to a memory file
SND_LOOP = 0x8, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x10, // don't stop any currently playing sound
SND_NOWAIT = 0x2000, // don't wait if the driver is busy
SND_ALIAS = 0x10000, // name is a registry alias
SND_ALIAS_ID = 0x110000,// alias is a predefined ID
SND_FILENAME = 0x20000, // name is file name
SND_RESOURCE = 0x40004, // name is resource name or atom
}; public class Sound
{
[DllImport("winmm.dll", SetLastError=true)]
public static extern bool PlaySound(string pszSound,System.IntPtr hmod,PlaySoundFlags flags); public static void Beep() {
Play("文件路径");
} public static void Play(string fileName) {
try {
PlaySound(fileName, IntPtr.Zero, (int)(PlaySoundFlags.SND_FILENAME | PlaySoundFlags.SND_SYNC));
} catch (Exception ex) {
MessageBox.Show("Can't play sound file. " + ex.ToString());
}
}
}这是我从论坛上查到的编码,但在窗体程序中不播放音乐,只“笃“的一声响,请高手指点一下,谢谢!
解决方案 »
- 滑动条在datagridview内?
- VS2005设置多个断点时,不能按F5跳到下个断点的问题
- 在winForm中怎么得到得到某个文件的路径
- 都有哪些原因为导到form.show()出来以后像死掉了一样呢?
- access 数据库 现在大概3w多条数据。一用like就数据溢出错误了??
- c# combobox tootip
- 这种是什么乱码 "学生"---"ѧÉú" "教师"---"½Ìʦ"
- 交互式绘图的问题
- 如何锁定界面
- 我要源码,我写的不能运行.
- 获取GridView中的数据问题
- ListView排序,Sorting属性设置不起作用!!!!!!!!!
[DllImport("winmm.dll", SetLastError=true)]
public static extern bool PlaySound(string pszSound,System.IntPtr hmod,int flags);调用
Sound.Play(@"C:\WINDOWS\Media\Windows XP Startup.wav");
SND_ASYNC = 0x1, // play asynchronously
SND_NODEFAULT = 0x2, // silence (!default) if sound not found
SND_MEMORY = 0x4, // pszSound points to a memory file
SND_LOOP = 0x8, // loop the sound until next sndPlaySound
SND_NOSTOP = 0x10, // don't stop any currently playing sound
SND_NOWAIT = 0x2000, // don't wait if the driver is busy
SND_ALIAS = 0x10000, // name is a registry alias
SND_ALIAS_ID = 0x110000,// alias is a predefined ID
SND_FILENAME = 0x20000, // name is file name
SND_RESOURCE = 0x40004, // name is resource name or atom
};这些变量是什么用的
怎么样建立播放列表