diff --git a/docs/tutorials/screen-resolution-detection.md b/docs/tutorials/screen-resolution-detection.md index 28cf52eaac..edd7902bb4 100644 --- a/docs/tutorials/screen-resolution-detection.md +++ b/docs/tutorials/screen-resolution-detection.md @@ -34,17 +34,10 @@ the `WinRT access` field to `All`. ### WebView2 -When using a WebView2 control in a UWP app, additional steps are required in -order to enable the screen resolution detection. First, the WebView2's user-agent -is the same as Edge Chromium and does not contain the term "Xbox One", so it has -to be manually added like this when initializing your WebView2: - -```CSharp -webView.CoreWebView2.Settings.UserAgent += " Xbox One"; -``` - -Also, you will need to add a special project called WinRTAdapter in your project's -solution. This project allows WinRT APIs to be exposed in the WebView2 control. +When using a WebView2 control in a UWP app, an additional step is required in +order to enable the screen resolution detection. You will need to add a special +project called WinRTAdapter in your project's solution. This project allows +WinRT APIs to be exposed in the WebView2 control. You will find more information on this [here](https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/winrt-from-js). Make sure you put `Windows.Media.Protection.ProtectionCapabilities` and `Windows.Media.Protection.ProtectionCapabilityResult` in the WinRTAdapter diff --git a/lib/util/platform.js b/lib/util/platform.js index f438396879..f739390270 100644 --- a/lib/util/platform.js +++ b/lib/util/platform.js @@ -765,46 +765,6 @@ shaka.util.Platform = class { shaka.log.alwaysWarn('Tizen: Error detecting screen size, default ' + 'screen size 1920x1080.'); } - } else if (Platform.isXboxOne()) { - maxResolution.width = 1920; - maxResolution.height = 1080; - try { - let winRT = undefined; - - // Try to access to WinRT for WebView, if it's not defined, - // try to access to WinRT for WebView2, if it's not defined either, - // let it throw. - if (typeof Windows !== 'undefined') { - winRT = Windows; - } else { - winRT = chrome.webview.hostObjects.sync.Windows; - } - - const protectionCapabilities = - new winRT.Media.Protection.ProtectionCapabilities(); - const protectionResult = - winRT.Media.Protection.ProtectionCapabilityResult; - // isTypeSupported may return "maybe", which means the operation is not - // completed. This means we need to retry - // https://learn.microsoft.com/en-us/uwp/api/windows.media.protection.protectioncapabilityresult?view=winrt-22621 - let result = null; - const type = - 'video/mp4;codecs="hvc1,mp4a";features="decode-res-x=3840,' + - 'decode-res-y=2160,decode-bitrate=20000,decode-fps=30,' + - 'decode-bpc=10,display-res-x=3840,display-res-y=2160,' + - 'display-bpc=8"'; - const keySystem = 'com.microsoft.playready.recommendation'; - do { - result = protectionCapabilities.isTypeSupported(type, keySystem); - } while (result === protectionResult.maybe); - if (result === protectionResult.probably) { - maxResolution.width = 3840; - maxResolution.height = 2160; - } - } catch (e) { - shaka.log.alwaysWarn('Xbox: Error detecting screen size, default ' + - 'screen size 1920x1080.'); - } } else if (Platform.isWebOS()) { try { const deviceInfo = @@ -851,6 +811,54 @@ shaka.util.Platform = class { maxResolution.width = 1920; maxResolution.height = 1080; } + } else { + // For Xbox and UWP apps. + let winRT = undefined; + try { + // Try to access to WinRT for WebView, if it's not defined, + // try to access to WinRT for WebView2, if it's not defined either, + // let it throw. + if (typeof Windows !== 'undefined') { + winRT = Windows; + } else { + winRT = chrome.webview.hostObjects.sync.Windows; + } + } catch (e) {} + if (winRT) { + maxResolution.width = 1920; + maxResolution.height = 1080; + try { + const protectionCapabilities = + new winRT.Media.Protection.ProtectionCapabilities(); + const protectionResult = + winRT.Media.Protection.ProtectionCapabilityResult; + // isTypeSupported may return "maybe", which means the operation + // is not completed. This means we need to retry + // https://learn.microsoft.com/en-us/uwp/api/windows.media.protection.protectioncapabilityresult?view=winrt-22621 + let result = null; + const type = + 'video/mp4;codecs="hvc1,mp4a";features="decode-res-x=3840,' + + 'decode-res-y=2160,decode-bitrate=20000,decode-fps=30,' + + 'decode-bpc=10,display-res-x=3840,display-res-y=2160,' + + 'display-bpc=8"'; + const keySystem = 'com.microsoft.playready.recommendation'; + do { + result = protectionCapabilities.isTypeSupported(type, keySystem); + } while (result === protectionResult.maybe); + if (result === protectionResult.probably) { + maxResolution.width = 3840; + maxResolution.height = 2160; + } + } catch (e) { + shaka.log.alwaysWarn('Xbox: Error detecting screen size, default ' + + 'screen size 1920x1080.'); + } + } else if (Platform.isXboxOne()) { + maxResolution.width = 1920; + maxResolution.height = 1080; + shaka.log.alwaysWarn('Xbox: Error detecting screen size, default ' + + 'screen size 1920x1080.'); + } } return maxResolution; }