1 using System;
 2 using System.Runtime.InteropServices;
 3 using System.Resources;
 4 using System.IO;
 5
 6 namespace Moihang
 7 {
 8         public class SoundPlayer
 9         {
10                 //SND_FILENAME
11                 public const UInt32 SND_ASYNC = 1;
12                 public const UInt32 SND_FILENAME = 2;
13                 public const UInt32 SND_MEMORY = 4;
14
15                 [DllImport("Winmm.dll")]
16                 public static extern bool PlaySound(string sound, IntPtr hMod, UInt32 dwFlags);
17
18                 // Linux Afileplay
19                 [DllImport("libafileplay.so")]
20                 public static extern int PlaySoundFile(string fileName, int quietMode);
21
22                 public SoundPlayer()
23                 {
24                 }
25
26                 public static void PlayWaveFile(string fileName)
27                 {
28                         // Check if using Linux
29                         switch (Environment.OSVersion.Platform)
30                         {
31                                 case System.PlatformID.Win32NT:
32                                 case System.PlatformID.Win32Windows:
33                                         PlaySound(fileName,IntPtr.Zero, SND_ASYNC | SND_FILENAME);
34                                                 break;
35                                 default:
36                                         PlaySoundFile(fileName, 1);
37                                         break;
38                         }
39                 }
40
41         }
42 }