110,010
社区成员




static public class SoundPlay
{
[DllImport("winmm.dll")]
private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(string path, StringBuilder shortPath, int shortPathLength);
static public void Playsound(string s)
{
mciSendString("close all", null, 0, IntPtr.Zero);
string Pcommand;
StringBuilder shortPath = new StringBuilder(80);
GetShortPathName(s, shortPath, 80);
Pcommand = "open \"" + shortPath.ToString() + "\" type mpegvideo alias MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
Pcommand = "set MediaFile time format milliseconds";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
Pcommand = "play MediaFile";
mciSendString(Pcommand, null, 0, IntPtr.Zero);
}
}