问题
I'm using cordova-plugin-wkwebview-external-screen to playback inline media on a secondary screen (via AirPlay or HDMI adapter). The media loads fine but does not autoplay videos in the external webview. (autoplay works fine in primary webview)
In my config.xml I have the following:
<preference name="AllowInlineMediaPlayback" value="true" />
<preference name="MediaTypesRequiringUserActionForPlayback" value="none" />
I have attempted adding the following configuration in WKWebViewExternalScreen.m (lines 20-21):
- (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 TWO LINES
self.externalWebView.configuration.allowsInlineMediaPlayback = YES;// Updated 'true' to 'YES'
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;
}
I've tried programmatically triggering an HTML5 video.play()
after the second view is loaded. No dice.
How can I autoplay HTML5 videos in this second view? (I'm using Cordova CLI 10.0.0 & Cordova iOS 6.1.1)
UPDATE:
I've created a sample Cordova iOS Xcode project here. In Simulator, Menu > I/O > External Displays > 1280 x 720 (720p) will open secondary.html
the secondary WebView. BOTH index.html
and secondary.html
contain the VIDEO tag: <video src="img/fireandiceocean.mp4" preload autoplay playsinline loop />
. In the primary view, the video plays in a loop automatically as expected, but in the Extended Display, the video does not autoplay.
来源:https://stackoverflow.com/questions/65115592/cordova-ios-6-autoplay-video-in-external-screen