我正在WKWebView中加载视频。
var video_el = document.createElement('video');
video_el.controls = true;
video_el.setAttribute('webkit-playsinline', 'webkit-playsinline');// Fix fullscreen problem on IOS 8 and 9
video_el.setAttribute('playsinline', 'playsinline');// Fix fullscreen problem on IOS 10
video_el.src = ' https://video.com/playlist.m3u8';
video_el.style.width = "720px";
video_el.style.height = "480px";
video_el.style.position = 'absolute';
video_el.style.top = 0;
video_el.style.left = 0;
video_el.autoplay = true;
document.getElementById('app').appendChild(video_el);
当我尝试播放视频时,没有任何反应。
然后我将视频静音:
video_el.muted = true
视频静音播放。
然后我关闭静音,视频会自动暂停:
video_el.muted = false
尝试按控件,视频或以编程方式按播放会导致从播放到暂停的停顿。
video_el.play();
这也是我的WKWebView配置:
- (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)settings
{
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
configuration.processPool = [[CDVWKProcessPoolFactory sharedFactory] sharedProcessPool];
if (settings == nil) {
return configuration;
}
configuration.allowsInlineMediaPlayback = YES;
configuration.mediaPlaybackRequiresUserAction = NO;
configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];
return configuration;
}
答案 0 :(得分:0)
原来,罪魁祸首与背景模式有关。 我使用的是后台插件(https://github.com/katzer/cordova-plugin-background-mode),启用该插件后,播放后视频会暂停:
cordova.plugins.backgroundMode.enable();
在播放视频时将其关闭可以解决问题。
cordova.plugins.backgroundMode.disable();