不能用控件,防止播放的时候出现延时
或者能够提供内存方法存放声音数据
目的就是能够十分准确的播放声音,不会出现声音的延迟现象
[dllimport("winmm.dll")]
public static extern long playsound(string name,long module,long flag);
[dllimport("winmm.dll")]
private static extern long mcisendstring(string lpstrcommand,string lpstrreturnstring,long length,long hwndcallback);
private string m_musicname="";
private void playmusic()
{
m_musicname="/""+tool.readinfo("promptmusicfile")+"/"";
if(m_musicname.length==0)
return;
try
{
mcisendstring(@"close " + m_musicname,"",0,0);
mcisendstring(@"open " + m_musicname,"",0,0);
mcisendstring(@"play " + m_musicname ,"",0,0);
}
catch
{
}
}
private void stopmusic()
{
try
{
mcisendstring(@"close " + m_musicname,"",0,0);
}
catch{}
}
播放内存中的wav文件可以这样:
//api定义
private const int snd_async = 0x1;
private const int snd_memory = 0x4;
[dllimport("winmm.dll")]
private static extern int sndplaysounda(byte[] lpszsoundname, int uflags);
//将blip1.wav添加入工程并设置为嵌入的资源
//现在是将它读入内存备用
type t=this.gettype();
system.reflection.assembly a=t.assembly;
system.io.stream stream=a.getmanifestresourcestream(t.namespace+".blip1.wav");
byte[] ba=new byte[stream.length];
stream.read(ba,0, ba.length);
stream.close();
//播放缓存
sndplaysounda(ba, snd_memory);
新闻热点
疑难解答