Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Xbox): Simplify the use of WebView2 #7743

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions docs/tutorials/screen-resolution-detection.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
88 changes: 48 additions & 40 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,46 +780,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 =
Expand Down Expand Up @@ -866,6 +826,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;
}
Expand Down
Loading