http://expert.csdn.net/Expert/TopicView1.asp?id=1705200有我的部分公用类,其中有个播放声音类就有SND_PURGE 的定义和用法示例(在how use this? 的region 段)
解决方案 »
- C#的一个小问题??
- 请问如何实现分组框内的空间使用统一的处理函数?
- .Net开发的软件,用什么加壳工具好?
- 求全国地区的数据最好是access的
- row["ID"]与row["ID",DtaRowVersion.Original]的区别?
- C# 调用java服务问题(Fault occurred while processing.)
- 如何用C#打开应用程序(如TXT文件)
- 哪位兄弟帮帮忙,提供一个InfragisticsNetAdvantage For.Net2004 vol 1 Full Releases的下载地址...
- C# Timer的疑问
- 怎样把string转换成int阿?
- 请教正则表达式!
- 安装duwamish7.0的失败问题
PlaySound("welcome.wav",0,0x40 | 0x00040004);
然后在button_click()里面加入PlaySound(null, IntPtr.Zero, 0);但是我发现程序总是在
PlaySound("welcome.wav",IntPtr.Zero,0x40 );执行完以后才开始运行button_click(),所以PlaySound(null, IntPtr.Zero, 0);这个终止声音文件播放函数也起不了作用,应该如何让PlaySound运行是来响应我的其他函数阿?谢谢!!!
PlaySound(ref mySound,IntPtr.Zero,0x40|0x04|0x02);其中的0x40 就是SND_PURGE 指示用于中止
0x04 是指SND_MEMORY 播放内容中的声音byte 流
0x02 指SND_NODEFAULT 如果该byte 流不可用或其它原因造成源错误时不播放默认声音警告
PlaySound(ref mySound[0],IntPtr.Zero,0x40|0x04|0x02);为此我特意写了个程序给你参考,如下的控制台程序,可编译参考:using System;
using System.Threading;
using System.Runtime.InteropServices;namespace soundtst
{
public class sndPlay { [DllImport("winmm.dll", EntryPoint="PlaySound")]
public static extern bool PlaySound(ref Byte snd, IntPtr hmod, uint fdwSound);
[DllImport("winmm.dll", EntryPoint="PlaySound")]
public static extern int PlaySound(string lpszName,int hModule,int dwFlags); public enum PlayingFlags :uint {
SND_SYNC = 0x00,
SND_ASYNC = 0x01,
SND_NODEFAULT = 0x02,
SND_MEMORY = 0x04,
SND_ALIAS = 0x010000,
SND_FILENAME = 0x020000,
SND_RESOURCE = 0x040004,
SND_ALIAS_ID = 0x0110000,
SND_ALIAS_START = 0,
SND_LOOP = 0x08,
SND_NOSTOP = 0x010,
SND_VALID = 0x01F,
SND_NOWAIT = 0x02000,
SND_PURGE = 0x40
}
} class Class1
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("now Start Play");
sndPlay.PlaySound(
@"Welcome.wav", /*文件名自己改*/
0,
(int)sndPlay.PlayingFlags.SND_ASYNC | (int)sndPlay.PlayingFlags.SND_LOOP
); Console.WriteLine("now Sleep 5 sec");
Thread.Sleep(5 * 1000); Console.WriteLine("now stop it");
byte[] mySound = new System.Byte[]{0};
sndPlay.PlaySound(ref mySound[0],IntPtr.Zero,0x40|0x04|0x02); Console.WriteLine("wait 5 sec to END");
Thread.Sleep(5 * 1000);
}
}
}
sndPlay.PlaySound(ref mySound[0],IntPtr.Zero,0x40|0x04|0x02);来中止总之,不管哪种声明,付源为空值,然后标志上使用 0x40 就可以了,如果不使用也可以中止,但是不会消毁资源并关闭文件关联。
不能实现声音文件的连读,比如:
for(schoolinfNum=0;school[0+schoolinfNum]!=null;schoolinfNum++)
{
sndPlay.PlaySound(school[0+schoolinfNum],0,
(int)sndPlay.PlayingFlags.SND_ASYNC);
}
sndPlay.PlaySound(1schoolinf.wav,0,
(int)sndPlay.PlayingFlags.SND_ASYNC);
school[]为string类型的数组,存放的是声音文件名,它就只会读最后一条“1schoolinf.wav”。而前面的因为playsound一运行就返回所以全部被pass了,因为我想实现的是如果用户按键的话就终止播放,如果没有按键的话就连续播放数组中存放所有声音文件这可以怎么实现阿?
但同时造成的问题是程序被挂起直到播放完成
所以我建议你开一个新线程来跑播放声音,那样就不影响主线程,从而两全其美
呵呵。不好意思,第一次提问题了