WKWebView 使用HTML 播放本地视频

来源:互联网 发布:淘宝店铺多久才能有钻 编辑:程序博客网 时间:2024/06/11 03:48

有时候需要使用WKWebView 来播放视频

-(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        }    }];}
原创粉丝点击