Beispiel #1
0
        public void PlaySound(NotificationSound sound, bool forceCustom = false)
        {
            try
            {
                var focused = false;

                App.MainForm.Invoke(() => focused = App.MainForm.ContainsFocus);

                if (!focused)
                {
                    SoundPlayer player = null;

                    if (forceCustom || AppSettings.ChatCustomHighlightSound)
                    {
                        try
                        {
                            var fileInfo = new FileInfo(Path.Combine(Util.GetUserDataPath(), "Custom", "Ping.wav"));
                            if (fileInfo.Exists)
                            {
                                if (fileInfo.LastWriteTime != highlightTimeStamp)
                                {
                                    HighlightSound?.Dispose();

                                    try
                                    {
                                        using (var stream = new FileStream(Path.Combine(Util.GetUserDataPath(), "Custom", "Ping.wav"), FileMode.Open))
                                        {
                                            HighlightSound = new SoundPlayer(stream);
                                            HighlightSound.Load();
                                        }

                                        player = HighlightSound;
                                        Console.WriteLine("loaded");
                                    }
                                    catch
                                    {
                                        HighlightSound.Dispose();
                                    }
                                }
                            }
                            else
                            {
                                player = HighlightSound;
                            }
                        }
                        catch { }
                    }

                    if (player == null)
                    {
                        player = defaultHighlightSound;
                    }

                    player.Play();
                }
            }
            catch { }
        }