Manchmal müssen Sie WKWebView zum Abspielen von Videos verwenden
-(instancetype)init {
self = [super init];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.opaque = NO;
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *html = @"<center><video id='load_success_video' width=\"100%\" height=\"100%\" controls><source src=\"load_success_video.mp4\" media=\"\"></video></center>";
[self loadHTMLString:html baseURL:baseURL];
self.frame = CGRectMake(0, 0, ScreenSize.width, ScreenSize.height);
self.configuration.allowsInlineMediaPlayback = YES;
self.configuration.allowsAirPlayForMediaPlayback = NO;
}
return self;
}
-(void)playVideo {
//call JS func to update JS content
NSString *js = [NSString stringWithFormat:@"document.getElementById('load_success_video').play()"];
[self evaluateJavaScript:js completionHandler:^(id _Nullable other, NSError * _Nullable error) {
if (error) {
#if DEBUG
NSLog(@"---call function %@ : %@", js, error.userInfo);
#endif
} else {
#if DEBUG
NSLog(@"---call js function %@ success", js);
#endif
}
}];
}