using System; using System.IO; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace KancolleSniffer.Util { public static class SoundPlayer { [DllImport("winmm.dll")] private static extern int mciSendString(String command, StringBuilder buffer, int bufferSize, IntPtr hWndCallback); // ReSharper disable InconsistentNaming // ReSharper disable once IdentifierTypo private const int MM_MCINOTIFY = 0x3B9; private const int MCI_NOTIFY_SUCCESSFUL = 1; // ReSharper restore InconsistentNaming public static void PlaySound(IntPtr handle, string file, int volume) { if (!File.Exists(file)) return; mciSendString("close sound", null, 0, IntPtr.Zero); if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0) return; mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero); mciSendString("play sound notify", null, 0, handle); } public static void CloseSound(Message m) { if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL) mciSendString("close sound", null, 0, IntPtr.Zero); } } }