Switch from NAudio to CSCore.
2 using System.Collections.Generic;
5 using System.Threading.Tasks;
6 using System.Diagnostics;
7 using System.Windows.Forms;
11 namespace SharpDisplayManager
13 class ConsumerElectronicControl
16 private PowerManager.SettingNotifier iPowerSettingNotifier;
18 public Cec.Client Client;
19 ///This flag will only work properly if both on and off events are monitored.
20 ///TODO: have a more solid implementation
21 public bool MonitorPowerOn;
24 public void TestSendKeys()
32 /// <param name="aWndHandle"></param>
33 /// <param name="aDeviceName"></param>
34 /// <param name="aHdmiPort"></param>
35 public void Start(IntPtr aWndHandle, string aDeviceName, byte aHdmiPort)
37 //Assuming monitor is on when we start up
38 MonitorPowerOn = true;
40 //Create our power setting notifier and register the event we are interested in
41 iPowerSettingNotifier = new PowerManager.SettingNotifier(aWndHandle);
42 iPowerSettingNotifier.OnMonitorPowerOn += OnMonitorPowerOn;
43 iPowerSettingNotifier.OnMonitorPowerOff += OnMonitorPowerOff;
46 Client = new Cec.Client(aDeviceName,aHdmiPort, CecDeviceType.PlaybackDevice);
54 if (iPowerSettingNotifier != null)
56 iPowerSettingNotifier.OnMonitorPowerOn -= OnMonitorPowerOn;
57 iPowerSettingNotifier.OnMonitorPowerOff -= OnMonitorPowerOff;
58 iPowerSettingNotifier = null;
72 private void ConnectCecClient()
74 //Our client takes care of closing before trying to connect
75 if (!Client.Open(1000))
77 Debug.WriteLine("WARNING: No CEC connection!");
81 private void OnMonitorPowerOn()
83 MonitorPowerOn = true;
84 //Trigger corresponding event thus executing associated actions
85 Properties.Settings.Default.EarManager.TriggerEvents<EventMonitorPowerOn>();
88 private void OnMonitorPowerOff()
90 MonitorPowerOn = false;
91 //Trigger corresponding event thus executing associated actions
92 Properties.Settings.Default.EarManager.TriggerEvents<EventMonitorPowerOff>();
96 /// We need to handle WM_POWERBROADCAST.
98 /// <param name="message"></param>
99 public void OnWndProc(ref Message message)
101 //Hook in our power manager
102 if (iPowerSettingNotifier != null)
104 iPowerSettingNotifier.WndProc(ref message);