zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
//  PBVideoPlayViewController.m
//  IphoneBIMe
//
//  Created by zjf on 2020/8/26.
//  Copyright © 2020 ProBIM. All rights reserved.
//
 
#import "PBVideoPlayViewController.h"
#import <WebKit/WebKit.h>
@interface PBVideoPlayViewController ()<WKUIDelegate, WKNavigationDelegate>
@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