1 class SPlayer
2 {
3 private static SoundPriorities _lastPriority = SoundPriorities.Low;
4
5 public static bool Play(string wavPath, SoundPriorities priority)
6 {
7 if (string.IsNullOrEmpty(wavPath)) return false;
8 if (!File.Exists(wavPath)) return false;
9 if (!wavPath.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)) return false;
10
11 if (priority >= _lastPriority)
12 {
13 Stop();
14 _lastPriority = priority;
15 return NativeMethods.PlaySoundA(wavPath, new IntPtr(), (int)(PlaySoundFlags.SND_ASYNC | PlaySoundFlags.SND_LOOP));
16 }
17
18 return false;
19 }
20
21 public static void Stop()
22 {
23 if (NativeMethods.PlaySoundA(null, new IntPtr(), 0))
24 _lastPriority = SoundPriorities.Low;
25 }
26 }
27
28 [Flags]
29 enum PlaySoundFlags : int
30 {
31