I am using wpf application inside one of the windows media player, so when I use the following code to detect HDMI connection it always show disconnect as that HDMI connection denotes as primary connection. When i use HDMI connection in laptop this work well, can some one suggest code chnages for above case
public static int HdmiConnectionStatus()
{
int HDMI_Monitors = 0;
ManagementClass mClass = new ManagementClass(@"\\localhost\ROOT\WMI:WmiMonitorConnectionParams");
Log.Info("HdmiConnectionStatus ManagementClass ");
if(mClass != null)
{
Log.Info(mClass);
foreach (ManagementObject mObject in mClass.GetInstances())
{
var ss = mObject["VideoOutputTechnology"];
Log.Info("HdmiConnectionStatus HDMI port Info :" ss);
if (ss.ToString().StartsWith("5"))
{
int HDMIport = Convert.ToInt32(ss);
if (HDMIport == 5)
{
HDMI_Monitors = 1;
}
}
}
}
else
{
Log.Info(" HdmiConnectionStatus Null ManagementClass ");
}
return HDMI_Monitors;
}
CodePudding user response:
I can see you are using very specific value 5 to get the HDMI connection, when you connect the HDMI cable in Laptop you will get two values in mObject , one will be laptop screen and another is HDMI value 5, but in case of setup box this case will not remain same, check the port number for your setup box , it can be 5 or 10 I tried on my setup box and I got value 10 and here is the code
public static int HdmiConnectionStatus()
{
int HDMI_Monitors = 0;
ManagementClass mClass = new ManagementClass(@"\\localhost\ROOT\WMI:WmiMonitorConnectionParams");
Log.Info("HdmiConnectionStatus ManagementClass ");
if(mClass != null)
{
Log.Info(mClass);
foreach (ManagementObject mObject in mClass.GetInstances())
{
var ss = mObject["VideoOutputTechnology"];
Log.Info("HdmiConnectionStatus HDMI port Info :" ss);
if (ss.ToString().StartsWith("5") || ss.ToString().StartWith("10"))
{
int HDMIport = Convert.ToInt32(ss);
if (HDMIport == 5 || HDMIport == 10)
{
HDMI_Monitors = 1;
}
}
}
}
else
{
Log.Info(" HdmiConnectionStatus Null ManagementClass ");
}
return HDMI_Monitors;
}