You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xbox设备Webview中部分WinRT函数调用失败Windows10运行正常问题咨询

Xbox端XAML + WebView项目JS调用WinRT API报错问题

我正在开发Xbox端托管应用安装部分的升级版本,不再使用旧的jsproj项目类型,改为采用XAML实现新项目。项目结构非常简单,单页面承载WebView来展示应用托管部分的内容。
在新应用中测试托管侧内容时,我发现WinRT存在异常表现:我们有大量调用WinRT的JavaScript代码,其中部分逻辑运行不符合预期,目前已发现至少两个函数调用失败,报错信息如下。

错误1(JavaScript)

try { 
  const applicationView = Windows.UI.ViewManagement.ApplicationView.getForCurrentView(); 
  applicationView.setDesiredBoundsMode( 
    Windows.UI.ViewManagement.ApplicationViewBoundsMode.useCoreWindow, 
  ); 
} catch (e) { 
  console.log(e); // Element not found 
} 

错误2(JavaScript)

try { 
  this.control = Windows.Media.SystemMediaTransportControls.getForCurrentView(); 
  this.control.isEnabled = true; 
  this.control.isFastForwardEnabled = true; 
  this.control.isNextEnabled = true; 
  this.control.isPauseEnabled = true; 
  this.control.isPlayEnabled = true; 
  this.control.isPreviousEnabled = true; 
  this.control.isRecordEnabled = true; 
  this.control.isRewindEnabled = true; 
  this.control.isStopEnabled = true; 
  this.control.isChannelUpEnabled = true; 
  this.control.isChannelDownEnabled = true; 
  this.control.playbackStatus = MediaPlaybackStatus.playing; 
  this.control.onbuttonpressed = this.onButtonPressed; 
} catch (e) { 
  console.log(e); 
  /* Invalid window handle. Could not find an appropriate view to be associated with this instance of the MediaPlaybackControl. Please make sure that a view has been initialized. */ 
}

同逻辑C#端运行正常

using Windows.UI.ViewManagement; 
using Windows.Media; 
... 
public MainPage() { 
  this.InitializeComponent(); 
  ApplicationView.GetForCurrentView()
    .SetDesiredBoundsMode(
      ApplicationViewBoundsMode.UseCoreWindow
    ); 
  this.control = SystemMediaTransportControls
    .GetForCurrentView(); 
} 
// code is happy

系统版本配置

最初使用的版本配置:

Target version: Windows 10, version 2004 (10.0; build 19041) 
Minimum version: Windows 10, version 1809 (10.0; build 17763) 

尝试降级后的版本配置:

Target version: Windows 10, version 1903 (10.0; build 18362) 
Minimum version: Windows 10, version 1809 (10.0; build 17763) 

异常表现

运行相同应用和相同托管内容时,在Windows10上不会出现这些错误,但部署到Xbox One或Xbox Series S|X上就会报错。猜测Windows10和Xbox使用的运行时版本不同,但降级目标版本也没有解决问题。

问题与补充说明

请问这些错误的成因是什么,有没有办法修复?
注:获取应用视图的调用我们可以舍弃,但我们需要客户端能够监听SystemMediaTransportControls的按键事件。我们当前的目标是先上线应用的安装部分,后续工作阶段再迭代更新托管部分的JavaScript代码,但目前新旧项目的WinRT运行逻辑看起来没有明确的对应关系。


内容的提问来源于stack exchange,提问作者Joshua Dannemann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 06:30:05