// // PBVideoPlayViewController.m // IphoneBIMe // // Created by zjf on 2020/8/26. // Copyright © 2020 ProBIM. All rights reserved. // #import "PBVideoPlayViewController.h" #import @interface PBVideoPlayViewController () @property (nonatomic, strong) WKWebView *webView; @end @implementation PBVideoPlayViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; } - (void)setupUI { PBBackNavItem *backNav = [PBBackNavItem backNacItem]; backNav.title = @"返回"; [backNav addTarget:self action:@selector(backNavAction) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backNavItem = [[UIBarButtonItem alloc] initWithCustomView:backNav]; self.navigationItem.leftBarButtonItem = backNavItem; self.view.backgroundColor = [UIColor greenColor]; self.title = @"视频"; self.webView = [[WKWebView alloc] init]; self.webView.navigationDelegate = self; self.webView.UIDelegate = self; [self.view addSubview:self.webView]; [self.webView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.bottom.left.right.equalTo(self.view); }]; if (self.url != nil && ![self.url isEqualToString:@""]) { [self loadWeb]; }else { [self playLocal]; } } - (void)loadWeb { NSLog(@"url:%@",self.url); [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.url]]]; } - (void)playLocal { [self.webView loadFileURL:self.filePath allowingReadAccessToURL:self.filePath]; } - (void)backNavAction { [self.navigationController popViewControllerAnimated:YES]; } - (void)setUrl:(NSString *)url { _url = url; } - (void)setFilePath:(NSURL *)filePath { _filePath = filePath; } // 页面开始加载时调用 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation { NSLog(@"页面开始加载时调用"); [YJProgressHUD showProgress:@"" inView:self.view]; } // 页面加载失败时调用 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error { NSLog(@"页面加载失败时调用%@",error); [YJProgressHUD showFailed:@"页面加载失败" inview:self.view]; } // 当内容开始返回时调用 - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation { NSLog(@"当内容开始返回时调用"); [YJProgressHUD hide]; } // 页面加载完成之后调用 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation { NSLog(@" 页面加载完成之后调用"); [YJProgressHUD hide]; } //提交发生错误时调用 - (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error { NSLog(@"提交发生错误时调用%@",error); } // 接收到服务器跳转请求即服务重定向时之后调用 - (void)webView:(WKWebView *)webView didReceiveServerRedirectForProvisionalNavigation:(WKNavigation *)navigation { } //进程被终止时调用 - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView{ NSLog(@"进程被终止时调用"); } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end