当前位置:编程学习 > C#/ASP.NET >>

一个优先级声音播放类

 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 

补充:软件开发 , C# ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,