diff --git a/Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.cpp b/Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.cpp index 173c217aa5..1e71de9e3f 100644 --- a/Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.cpp +++ b/Samples/DeviceEnumerationAndPairing/cpp/DisplayHelpers.cpp @@ -128,6 +128,24 @@ namespace SDKTemplate return ref new DeviceSelectorInfo("UPnP", DeviceClass::All, "System.Devices.Aep.ProtocolId:=\"{0e261de4-12f0-46e6-91ba-428607ccef64}\"", DeviceInformationKind::AssociationEndpoint); } + void AddVideoCastingIfSupported(Vector^ selectors) + { + try + { + selectors->Append(DeviceSelectorChoices::VideoCasting); + } + catch (Exception^ ex) + { + if (ex->HResult == HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED)) + { + // Video casting not supported by the system. + } + else + { + throw; + } + } + } IVectorView^ DeviceSelectorChoices::DevicePickerSelectors::get() { @@ -138,7 +156,7 @@ namespace SDKTemplate selectors->Append(BluetoothLEUnpairedOnly); selectors->Append(WiFiDirect); selectors->Append(PointOfServicePrinter); - selectors->Append(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors->Append(DialAllApps); return selectors->GetView(); @@ -161,7 +179,7 @@ namespace SDKTemplate selectors->Append(BluetoothLE); selectors->Append(WiFiDirect); selectors->Append(PointOfServicePrinter); - selectors->Append(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors->Append(DialAllApps); selectors->Append(Wsd); selectors->Append(Upnp); @@ -176,7 +194,7 @@ namespace SDKTemplate selectors->Append(BluetoothLEPairedOnly); selectors->Append(WiFiDirectPairedOnly); selectors->Append(PointOfServicePrinter); - selectors->Append(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors->Append(DialAllApps); selectors->Append(Wsd); selectors->Append(Upnp); @@ -191,7 +209,7 @@ namespace SDKTemplate selectors->Append(BluetoothLE); selectors->Append(WiFiDirect); selectors->Append(PointOfServicePrinter); - selectors->Append(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors->Append(Wsd); selectors->Append(Upnp); diff --git a/Samples/DeviceEnumerationAndPairing/cs/DisplayHelpers.cs b/Samples/DeviceEnumerationAndPairing/cs/DisplayHelpers.cs index 433b7da94a..b7c725913d 100644 --- a/Samples/DeviceEnumerationAndPairing/cs/DisplayHelpers.cs +++ b/Samples/DeviceEnumerationAndPairing/cs/DisplayHelpers.cs @@ -195,6 +195,18 @@ public static DeviceSelectorInfo Upnp } } + public static void AddVideoCastingIfSupported(List selectors) + { + try + { + selectors.Add(VideoCasting); + } + catch (Exception ex) when (ex.HResult == unchecked((int)0x80070032)) // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) + { + // Video casting is not supported by the system. + } + } + public static List DevicePickerSelectors { get @@ -207,7 +219,7 @@ public static List DevicePickerSelectors selectors.Add(BluetoothLEUnpairedOnly); selectors.Add(WiFiDirect); selectors.Add(PointOfServicePrinter); - selectors.Add(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors.Add(DialAllApps); return selectors; @@ -238,7 +250,7 @@ public static List DeviceWatcherSelectors selectors.Add(BluetoothLE); selectors.Add(WiFiDirect); selectors.Add(PointOfServicePrinter); - selectors.Add(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors.Add(DialAllApps); selectors.Add(Wsd); selectors.Add(Upnp); @@ -257,7 +269,7 @@ public static List BackgroundDeviceWatcherSelectors selectors.Add(BluetoothLEPairedOnly); selectors.Add(WiFiDirectPairedOnly); selectors.Add(PointOfServicePrinter); - selectors.Add(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors.Add(DialAllApps); selectors.Add(Wsd); selectors.Add(Upnp); @@ -279,7 +291,7 @@ public static List PairingSelectors selectors.Add(BluetoothLE); selectors.Add(WiFiDirect); selectors.Add(PointOfServicePrinter); - selectors.Add(VideoCasting); + AddVideoCastingIfSupported(selectors); selectors.Add(Wsd); selectors.Add(Upnp); diff --git a/Samples/DeviceEnumerationAndPairing/js/js/displayhelpers.js b/Samples/DeviceEnumerationAndPairing/js/js/displayhelpers.js index 37febab114..535d361049 100644 --- a/Samples/DeviceEnumerationAndPairing/js/js/displayhelpers.js +++ b/Samples/DeviceEnumerationAndPairing/js/js/displayhelpers.js @@ -36,7 +36,17 @@ var wiFiDirect = { displayName: "Wi-Fi Direct", selector: Windows.Devices.WiFiDirect.WiFiDirectDevice.getDeviceSelector(Windows.Devices.WiFiDirect.WiFiDirectDeviceSelectorType.associationEndpoint) }; var wiFiDirectPairedOnly = { displayName: "Wi-Fi Direct (paired)", selector: Windows.Devices.WiFiDirect.WiFiDirectDevice.getDeviceSelector() }; var pointOfServicePrinter = { displayName: "Point of Service Printer", selector: Windows.Devices.PointOfService.PosPrinter.getDeviceSelector() }; - var videoCasting = { displayName: "Video Casting", selector: Windows.Media.Casting.CastingDevice.getDeviceSelector(Windows.Media.Casting.CastingPlaybackTypes.video) }; + + try { + var videoCasting = { displayName: "Video Casting", selector: Windows.Media.Casting.CastingDevice.getDeviceSelector(Windows.Media.Casting.CastingPlaybackTypes.video) }; + } catch (e) { + if (e.number === 0x80070032 | 0) { // HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) + // Video casting not supported by the system. + } else { + throw e; + } + } + var dialAllApps = { displayName: "DIAL (All Apps)", selector: Windows.Media.DialProtocol.DialDevice.getDeviceSelector("") }; // WSD and UPnP are unique in that there are currently no general WSD or UPnP APIs to USE the devices once you've discovered them. @@ -53,7 +63,7 @@ devicePickerArray.push(bluetoothLEUnpairedOnly); devicePickerArray.push(wiFiDirect); devicePickerArray.push(pointOfServicePrinter); - devicePickerArray.push(videoCasting); + videoCasting && devicePickerArray.push(videoCasting); devicePickerArray.push(dialAllApps); var devicePickerSelectors = new WinJS.Binding.List(devicePickerArray); @@ -68,7 +78,7 @@ deviceWatcherArray.push(bluetoothLE); deviceWatcherArray.push(wiFiDirect); deviceWatcherArray.push(pointOfServicePrinter); - deviceWatcherArray.push(videoCasting); + videoCasting && deviceWatcherArray.push(videoCasting); deviceWatcherArray.push(dialAllApps); deviceWatcherArray.push(wsd); deviceWatcherArray.push(upnp); @@ -79,7 +89,7 @@ backgroundDeviceWatcherArray.push(bluetoothLEPairedOnly); backgroundDeviceWatcherArray.push(wiFiDirectPairedOnly); backgroundDeviceWatcherArray.push(pointOfServicePrinter); - backgroundDeviceWatcherArray.push(videoCasting); + videoCasting && backgroundDeviceWatcherArray.push(videoCasting); backgroundDeviceWatcherArray.push(dialAllApps); backgroundDeviceWatcherArray.push(wsd); backgroundDeviceWatcherArray.push(upnp); @@ -90,7 +100,7 @@ pairingArray.push(bluetoothLE); pairingArray.push(wiFiDirect); pairingArray.push(pointOfServicePrinter); - pairingArray.push(videoCasting); + videoCasting && pairingArray.push(videoCasting); pairingArray.push(wsd); pairingArray.push(upnp); var pairingSelectors = new WinJS.Binding.List(pairingArray);