Control
Cannot use control to prevent delay when playing
Or can provide memory methods for storing sound data
The goal is to be able to play the sound very accurately without any delay in sound
[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{}
}
Playback in-memory WAV files can be this way:
API definition
Private Const int snd_async = 0x1;
Private Const int snd_memory = 0x4;
[DllImport ("Winmm.dll")]
private static extern int Sndplaysounda (byte[] lpszsoundname, int uflags);
Add Blip1.wav to the project and set it as an embedded resource
Now read it into memory standby
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 ();
Play Cache
Sndplaysounda (BA, snd_memory);