【发布时间】:2020-11-27 05:50:21
【问题描述】:
我有一个 Cordova 应用程序,它使用这个插件 (cordova-plugin-wkwebview-external-screen) 通过 Airplay/HDMI 适配器在外部屏幕上全屏显示图像/媒体(类似于 Apple 的 Keynote)。
使用 UIwebview 一切正常,但我在使用 WKwebview 的外部屏幕上显示媒体时遇到问题。我现在使用的是 Cordova iOS 6.1.1 (CLI 10.0)。
我正在使用window.WkWebView.convertFilePath() 在我的主(控制)屏幕上显示媒体,但转换后的文件 url 和“file://...” url (cordova.file.dataDirectory + ‘image.jpg’) 在外部屏幕上都不起作用。
其他信息:
- 我的外屏是通过
ExternalScreen.loadHTML('secondary.html');启动的,但外屏的窗口中似乎没有Cordova 可用(即使在secondary.html 中包含了cordova.js)。 - 我的 index.html(控制)和 secondary.html(显示)文档中的“白名单”元数据是相同的。
如何获得将显示在我的第二个(外部)屏幕上的图像 URL?
更新:
我更新了plugin 的getWebView 函数,添加了allowFileAccessFromFileURLs、allowUniversalAccessFromFileURLs、allowsInlineMediaPlayback 和mediaTypesRequiringUserActionForPlayback 配置:
- (WKWebView*)getWebView {
if (!self.externalWebView) {
UIScreen* externalScreen = [[UIScreen screens] objectAtIndex: 1];
CGRect screenBounds = externalScreen.bounds;
self.externalWebView = [[WKWebView alloc] initWithFrame: screenBounds configuration: [[WKWebViewConfiguration alloc] init]];
// I added these four configurations...
[self.externalWebView.configuration.preferences setValue:@YES forKey:@"allowFileAccessFromFileURLs"];
[self.externalWebView.configuration setValue:@YES forKey:@"allowUniversalAccessFromFileURLs"];
self.externalWebView.configuration.allowsInlineMediaPlayback = TRUE;
self.externalWebView.configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
self.externalWindow = [[UIWindow alloc] initWithFrame: screenBounds];
self.externalWindow.screen = externalScreen;
self.externalWindow.clipsToBounds = YES;
[self.externalWindow addSubview:self.externalWebView];
[self.externalWindow makeKeyAndVisible];
self.externalWindow.hidden = NO;
}
return self.externalWebView;
}
不幸的是,这些更改不会似乎影响externalView。我暂时使用这个插件作为解决方法 (cordova-plugin-wkwebview-sandbox-webserver),但即使这样我也无法让 HTML5 视频自动播放 - 所以我怀疑我是否将配置设置放在正确的位置?
【问题讨论】: