DWVodPlayViewController.m 22.7 KB
Newer Older
Han Ruisong's avatar
Han Ruisong committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
//
//  DWVodPlayViewController.m
//  Demo
//
//  Created by zwl on 2019/4/15.
//  Copyright © 2019 com.bokecc.www. All rights reserved.
//

#import "DWVodPlayViewController.h"
#import "DWVodPlayTableViewCell.h"
#import "DWVodPlayBottomView.h"
#import "DWVodPlayerView.h"
#import "DWAdShouView.h"
#import "DWNetworkMonitorViewController.h"
Han Ruisong's avatar
Han Ruisong committed
15
16
#import "DWScreeningListViewController.h"
#import "DWScreeningBgView.h"
Han Ruisong's avatar
Han Ruisong committed
17
18
19
20
21
22

typedef enum : NSUInteger {
    DWVodPlayTableViewCellStyleDefault,
    DWVodPlayTableViewCellStyleChoose,
} DWVodPlayTableViewCellStyle;

Han Ruisong's avatar
Han Ruisong committed
23
@interface DWVodPlayViewController ()<UITableViewDelegate,UITableViewDataSource,DWVodPlayBottomViewDelegate,DWVodPlayerViewDelegate,DWAdShouViewDelegate,DWScreeningListViewControllerDelegate,DWScreeningBgViewDelegate>
Han Ruisong's avatar
Han Ruisong committed
24
25
26
27
28
29
30
31
32
33

@property(nonatomic,assign)CGSize playerViewSize;
@property(nonatomic,strong)DWVodPlayerView * playerView;
@property(nonatomic,strong)UITableView * listTableView;
@property(nonatomic,strong)DWVodPlayBottomView * bottomView;

@property(nonatomic,assign)DWVodPlayTableViewCellStyle cellStyle;

@property(nonatomic,strong)DWAdShouView * adShowView;//广告

Han Ruisong's avatar
Han Ruisong committed
34
35
@property(nonatomic,strong)DWScreeningBgView * screenBgView;//投屏控制器

Hanruisong's avatar
Hanruisong committed
36
37
@property(nonatomic,assign)BOOL isLock;

Han Ruisong's avatar
Han Ruisong committed
38
39
40
41
42
43
44
45
46
47
48
49
@end

@implementation DWVodPlayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initParams];
    [self initUI];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChangeNotification) name:UIDeviceOrientationDidChangeNotification object:nil];
Han Ruisong's avatar
Han Ruisong committed
50
51
52
53
54
55
56
57
58
    
    //判断是否小窗播放
    if (DWAPPDELEGATE.vodPlayerView) {
        if ([DWAPPDELEGATE.vodPlayerView.videoModel.videoId isEqualToString:self.vodModel.videoId]) {
            //当前正在窗口播放的视频
            return;
        }
    }
    
Han Ruisong's avatar
Han Ruisong committed
59
60
61
    DWConfigurationManager * manager = [DWConfigurationManager sharedInstance];
    if (manager.isOpenAd) {
        //广告模式
Hanruisong's avatar
Hanruisong committed
62
        [self startRequestAdInfo:1];
Han Ruisong's avatar
Han Ruisong committed
63
64
65
66
67
68
69
70
71
72
    }else{
        //正常播放
        [self startRequestVideo:self.vodModel.videoId];
    }

}

-(void)startRequestVideo:(NSString *)videoId
{
    __weak typeof(self) weakSelf = self;
Han Ruisong's avatar
Han Ruisong committed
73

Han Ruisong's avatar
Han Ruisong committed
74
75
76
77
    DWPlayInfo * playInfo = [[DWPlayInfo alloc]initWithUserId:[DWConfigurationManager sharedInstance].DWAccount_userId andVideoId:videoId key:[DWConfigurationManager sharedInstance].DWAccount_apikey hlsSupport:@"1"];
    playInfo.timeoutSeconds = 30;
    //音频 + 视频数据,这里仅做示范,可根据自己项目业务逻辑来调整
    playInfo.mediatype = @"0";
Han Ruisong's avatar
Han Ruisong committed
78
    //开启授权验证功能传入
Han Ruisong's avatar
Han Ruisong committed
79
    playInfo.verificationCode = [DWConfigurationManager sharedInstance].verification;
Han Ruisong's avatar
Han Ruisong committed
80
81
    //客户端用户id,选填
//    playInfo.roleId = @"";
Han Ruisong's avatar
Han Ruisong committed
82
83
84
85
86
87
88
89
90
91
92
93
    playInfo.finishBlock = ^(DWVodVideoModel *vodVideo) {
        NSLog(@"%@",vodVideo);
        //下载时,保存图片,名字等数据
        weakSelf.playerView.vodModel = weakSelf.vodModel;
        [weakSelf.playerView setVodVideo:vodVideo];
    };
    playInfo.errorBlock = ^(NSError *error) {
        [error.localizedDescription showAlert];
    };
    [playInfo start];
}

Hanruisong's avatar
Hanruisong committed
94
95
//1片头广告,2暂停广告,3片尾广告
-(void)startRequestAdInfo:(int)type
Han Ruisong's avatar
Han Ruisong committed
96
97
{
    __weak typeof(self) weakSelf = self;
Hanruisong's avatar
Hanruisong committed
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    DWAdInfo * adInfo = [[DWAdInfo alloc]initWithUserId:[DWConfigurationManager sharedInstance].DWAccount_userId andVideoId:self.vodModel.videoId type:[NSString stringWithFormat:@"%d",type]];
    [adInfo start];
    adInfo.finishBlock = ^(DWVodAdInfoModel *adInfo) {
        //若获取完广告信息时,没有显示广告视图,不加载广告
        if (!weakSelf.adShowView.hidden) {
            weakSelf.playerView.isShowAd = NO;
            return;
        }
        
        [weakSelf.adShowView playAdVideo:adInfo];
    };
    adInfo.errorBlock = ^(NSError *error) {
        
        weakSelf.playerView.isShowAd = NO;

        //片尾广告请求失败,继续播放下一集
        if (type == 3) {
            [weakSelf.playerView playNextVideo];
            return;
        }
        
        if (type == 1) {
            [weakSelf startRequestVideo:weakSelf.vodModel.videoId];
        }
        
//        [@"广告请求失败" showAlert];
//        [error.localizedDescription showAlert];
    };

    self.playerView.isShowAd = YES;
Han Ruisong's avatar
Han Ruisong committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = YES;
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

-(void)dealloc
{
    NSLog(@"DWVodPlayViewController dealloc");
    
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}

-(void)screenOrientationDidChange:(BOOL)isFull
{
    self.listTableView.hidden = isFull;
    self.bottomView.hidden = isFull;
    
    if (isFull) {
        [_playerView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.and.top.equalTo(@0);
            make.right.and.bottom.equalTo(@0);
        }];
        
        [_adShowView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.and.top.equalTo(@0);
            make.right.and.bottom.equalTo(@0);
        }];
Han Ruisong's avatar
Han Ruisong committed
170
171
172
173
174
175
176
177
        
        if (self.screenBgView) {
            [_screenBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.and.top.equalTo(@0);
                make.right.and.bottom.equalTo(@0);
            }];

        }
Han Ruisong's avatar
Han Ruisong committed
178
179
180
181
182
183
184
185
186
187
    }else{
        [_playerView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.and.left.equalTo(@0);
            make.width.equalTo(@(self.playerViewSize.width));
            make.height.equalTo(@(self.playerViewSize.height));
        }];
        
        [_adShowView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.and.left.equalTo(@0);
            make.width.equalTo(@(self.playerViewSize.width));
Hanruisong's avatar
Hanruisong committed
188
            make.height.equalTo(@(self.playerViewSize.height - 40));
Han Ruisong's avatar
Han Ruisong committed
189
        }];
Han Ruisong's avatar
Han Ruisong committed
190
191
192
193
194
195
196
197
        
        if (self.screenBgView) {
            [_screenBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.and.left.equalTo(@0);
                make.width.equalTo(@(self.playerViewSize.width));
                make.height.equalTo(@(self.playerViewSize.height));
            }];
        }
Han Ruisong's avatar
Han Ruisong committed
198
199
200
201
    }
    
    [self.adShowView screenRotate:isFull];
    [self.playerView reLayoutWithScreenState:isFull];
Han Ruisong's avatar
Han Ruisong committed
202
203
204
205

    if (self.screenBgView) {
        [self.screenBgView screenRotate:isFull];
    }
Han Ruisong's avatar
Han Ruisong committed
206
207
208
209
210
}

#pragma mark - notification
-(void)deviceOrientationChangeNotification
{
Hanruisong's avatar
Hanruisong committed
211
212
213
214
    if (self.isLock) {
        return;
    }
    
Han Ruisong's avatar
Han Ruisong committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
    UIInterfaceOrientation interfaceOrientation = (UIInterfaceOrientation)orientation;
    
    switch (interfaceOrientation) {
        case UIInterfaceOrientationUnknown:{
            break;
        }
        case UIInterfaceOrientationPortrait:{
            [self screenOrientationDidChange:NO];
            break;
        }
        case UIInterfaceOrientationLandscapeLeft:{
            [self screenOrientationDidChange:YES];
            break;
        }
        case UIInterfaceOrientationLandscapeRight:{
            [self screenOrientationDidChange:YES];
            break;
        }
        default:
            break;
    }
}

#pragma mark - DWAdShouViewDelegate
-(void)adShowPlayDidFinish:(DWAdShouView*)adShowView AndAdType:(NSInteger)type
{
Hanruisong's avatar
Hanruisong committed
242
243
    self.playerView.isShowAd = NO;

Han Ruisong's avatar
Han Ruisong committed
244
245
246
247
248
249
250
251
252
    if (type == 1) {
        //片头广告结束,播放正片
        [self startRequestVideo:self.vodModel.videoId];
    }
    
    if (type == 2) {
        //暂停广告结束,继续播放
        [self.playerView play];
    }
Hanruisong's avatar
Hanruisong committed
253
254
255
256
257
258
    
    if (type == 3) {
        //片尾广告结束,播放下一集
        [self.playerView playNextVideo];
    }
    
Han Ruisong's avatar
Han Ruisong committed
259
260
261
262
}

-(void)adShowPlay:(DWAdShouView*)adShowView DidScreenRotate:(BOOL)isFull
{
Hanruisong's avatar
Hanruisong committed
263
264
265
266
267
    if (isFull) {
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
    }else{
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
    }
Han Ruisong's avatar
Han Ruisong committed
268
269
270
271
272
273
274
}

#pragma mark - DWVodPlayerViewDelegate
//返回事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView ReturnBackAction:(BOOL)isFull
{
    if (!isFull) {
Han Ruisong's avatar
Han Ruisong committed
275
        DWAPPDELEGATE.vodPlayerView = nil;
Han Ruisong's avatar
Han Ruisong committed
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
        [self.playerView closePlayer];
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
    }
}

//播放状态改变事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView PlayStatus:(BOOL)isPlaying
{
    if (![DWConfigurationManager sharedInstance].isOpenAd) {
        return;
    }
    
    if (!isPlaying) {
        //播放暂停广告
Hanruisong's avatar
Hanruisong committed
292
        [self startRequestAdInfo:2];
Han Ruisong's avatar
Han Ruisong committed
293
    }else{
Hanruisong's avatar
Hanruisong committed
294
295
296
297
        if (!self.adShowView.hidden) {
            [self.adShowView adFinish];
        }
        self.playerView.isShowAd = NO;
Han Ruisong's avatar
Han Ruisong committed
298
299
300
301
302
303
    }
}

//选集选择事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView ChooseSelection:(NSInteger)selectionIndex
{
Hanruisong's avatar
Hanruisong committed
304
305
    [self.playerView saveSliderSchedule];
    
Han Ruisong's avatar
Han Ruisong committed
306
307
308
309
310
311
312
313
314
    DWVodModel * vodModel = [self.vidoeList objectAtIndex:selectionIndex];
    self.vodModel = vodModel;
    [self startRequestVideo:self.vodModel.videoId];
    [self.listTableView reloadData];
}

//播放下一集事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView NextSelection:(NSInteger)nextIndex
{
Hanruisong's avatar
Hanruisong committed
315
316
317
318
319
    if (!self.adShowView.hidden) {
        [self.adShowView adFinish];
    }
    self.playerView.isShowAd = NO;

Han Ruisong's avatar
Han Ruisong committed
320
321
    DWVodModel * vodModel = [self.vidoeList objectAtIndex:nextIndex];
    self.vodModel = vodModel;
Hanruisong's avatar
Hanruisong committed
322
323
324
325
326
327
328
329
    DWConfigurationManager * manager = [DWConfigurationManager sharedInstance];
    if (manager.isOpenAd) {
        //广告模式
        [self startRequestAdInfo:1];
    }else{
        //正常播放
        [self startRequestVideo:self.vodModel.videoId];
    }
Han Ruisong's avatar
Han Ruisong committed
330
331
332
    [self.listTableView reloadData];
}

Han Ruisong's avatar
Han Ruisong committed
333
334
335
336
337
338
339
340
341
342
343
//投屏事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView ScreeningJumpAction:(NSString *)playUrl
{
    DWScreeningListViewController * screeningListVC = [[DWScreeningListViewController alloc]init];
    screeningListVC.playUrl = playUrl;
    screeningListVC.delegate = self;
    [self.navigationController pushViewController:screeningListVC animated:YES];
    
    self.playerView.isScreening = YES;
}

Han Ruisong's avatar
Han Ruisong committed
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
//网络检测事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView DidNetworkMonitor:(NSString *)vid AndPlayUrl:(NSString *)playUrl
{
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];

    DWNetworkMonitorViewController * networkMonitorVC = [[DWNetworkMonitorViewController alloc]initWithVideoId:vid];
    networkMonitorVC.currentPlayurl = playUrl;
    [self.navigationController pushViewController:networkMonitorVC animated:YES];
}

//访客信息收集器,退出填写
-(void)vodPlayerViewVisitorReturnBack:(DWVodPlayerView *)playerView
{
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];

    [self.playerView closePlayer];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.navigationController popViewControllerAnimated:YES];
    });
}

Han Ruisong's avatar
Han Ruisong committed
366
367
368
369
//窗口模式播放
-(void)vodPlayerViewDidEnterWindowsModel:(DWVodPlayerView *)playerView
{
    //如果开启了小窗,开小窗,没开启正常
Han Ruisong's avatar
Han Ruisong committed
370
    DWAPPDELEGATE.vodPlayerView = self.playerView;
Han Ruisong's avatar
Han Ruisong committed
371
372
373
374
    [DWAPPDELEGATE.vodPlayerView enterWindowsModel];
    [self.navigationController popViewControllerAnimated:YES];
}

Hanruisong's avatar
Hanruisong committed
375
376
377
378
379
380
381
//片尾广告事件
-(void)vodPlayerViewEndAd:(DWVodPlayerView *)playerView
{
//    NSLog(@"准备请求片尾广告 %@",self.vodModel.videoId);
    [self startRequestAdInfo:3];
}

Hanruisong's avatar
Hanruisong committed
382
383
384
385
386
387
//锁屏事件
-(void)vodPlayerViewLockScreen:(BOOL)isLock
{
    self.isLock = isLock;
}

Han Ruisong's avatar
Han Ruisong committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
#pragma mark - 投屏相关
-(void)screeningReturnButtonAction
{
    self.playerView.isScreening = NO;
}

-(void)screeningListDidSelectAction:(DWUPnPDevice *)device AndPlayUrl:(NSString *)playUrl
{
    self.screenBgView = [[DWScreeningBgView alloc]initWithDevice:device AndPlayUrl:playUrl];
    self.screenBgView.delegate = self;
    self.screenBgView.title = self.playerView.videoTitle;
    self.screenBgView.seekTime = self.playerView.currentPlayDuration;
    [self.view addSubview:self.screenBgView];
    [_screenBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.equalTo(@0);
        make.width.equalTo(@(self.playerViewSize.width));
        make.height.equalTo(@(self.playerViewSize.height));
    }];
    
}

-(void)screeningBgViewCloseAction
{
Hanruisong's avatar
Hanruisong committed
411
412
    self.playerView.isScreening = NO;

Han Ruisong's avatar
Han Ruisong committed
413
414
415
416
417
418
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.screenBgView removeFromSuperview];
        self.screenBgView = nil;
    });
}

Han Ruisong's avatar
Han Ruisong committed
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#pragma mark - tabelViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.vidoeList.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 7.5 + 90 + 7.5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString * identifier = self.cellStyle == DWVodPlayTableViewCellStyleDefault ? @"CellStyleDefault" : @"CellStyleChoose";
    DWVodPlayTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[DWVodPlayTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    DWVodModel * vodModel = [self.vidoeList objectAtIndex:indexPath.row];
    [cell setVodModel:vodModel AndPlaying:[vodModel.videoId isEqualToString:self.vodModel.videoId]];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
Han Ruisong's avatar
Han Ruisong committed
448
449
450
451
452
453
    if (self.playerView.isScreening) {
        //正在投屏
        [@"正在投屏中,请退出投屏再切换视频" showAlert];
        return;
    }
    
Han Ruisong's avatar
Han Ruisong committed
454
455
456
457
458
459
460
    DWVodModel * vodModel = [self.vidoeList objectAtIndex:indexPath.row];
    
    if ([vodModel.videoId isEqualToString:self.vodModel.videoId]) {
        [@"当前正在播放此集" showAlert];
        return;
    }
    
Hanruisong's avatar
Hanruisong committed
461
462
463
464
    if (!self.adShowView.hidden) {
        [self.adShowView adFinish];
    }
    self.playerView.isShowAd = NO;
Hanruisong's avatar
Hanruisong committed
465
466
    
    [self.playerView saveSliderSchedule];
Hanruisong's avatar
Hanruisong committed
467

Han Ruisong's avatar
Han Ruisong committed
468
    self.vodModel = vodModel;
Hanruisong's avatar
Hanruisong committed
469
470
471
472
473
474
475
476
477
478
479
    DWConfigurationManager * manager = [DWConfigurationManager sharedInstance];
    if (manager.isOpenAd) {
        //广告模式
        [self startRequestAdInfo:1];
    }else{
        //正常播放
        [self startRequestVideo:self.vodModel.videoId];
    }
    
//    self.vodModel = vodModel;
//    [self startRequestVideo:self.vodModel.videoId];
Han Ruisong's avatar
Han Ruisong committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
    
    [tableView reloadData];
}

#pragma mark - bottomViewDelegate
-(void)vodPlayBottomViewDownloadButtonAction
{
    self.cellStyle = DWVodPlayTableViewCellStyleChoose;
    [self.listTableView reloadData];
}
    
-(void)vodPlayBottomViewSureButtonAction
{
    self.cellStyle = DWVodPlayTableViewCellStyleDefault;
    [self.listTableView reloadData];
    
    NSMutableArray * downloadArray = [NSMutableArray array];
    [self.vidoeList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        DWVodModel * vodModel = (DWVodModel *)obj;
        if (vodModel.isSelect) {
            [downloadArray addObject:vodModel.videoId];
        }
    }];
    
    if (downloadArray.count == 0) {
        [@"请选择下载视频" showAlert];
        return;
    }
    
    //批量下载
    DWBatchDownloadUtility * bdUtility = [[DWBatchDownloadUtility alloc]initWithUserId:[DWConfigurationManager sharedInstance].DWAccount_userId key:[DWConfigurationManager sharedInstance].DWAccount_apikey AndVideoIds:downloadArray];
    bdUtility.verificationCode = [DWConfigurationManager sharedInstance].verification;
    //音频 + 视频数据,这里仅做示范,可根据自己项目业务逻辑来调整
    bdUtility.mediatype = @"0";
Han Ruisong's avatar
Han Ruisong committed
514
    __weak typeof(self) weakSelf = self;
Han Ruisong's avatar
Han Ruisong committed
515
516
517
518
519
520
521
    bdUtility.finishBlock = ^(NSArray<DWVodVideoModel *> * _Nonnull playInfosArray) {
        
        if (playInfosArray.count == 0) {
            [@"未获取到视频数据" showAlert];
            return;
        }
        
Han Ruisong's avatar
Han Ruisong committed
522
        [weakSelf startDownloadTask:playInfosArray];
Han Ruisong's avatar
Han Ruisong committed
523
524
525
526
527
528
529
530
    };
    
    bdUtility.errorBlock = ^(NSError * _Nonnull error) {
        [error.localizedDescription showAlert];
    };
    [bdUtility start];

}
Han Ruisong's avatar
Han Ruisong committed
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581

-(void)startDownloadTask:(NSArray<DWVodVideoModel *> *)playInfosArray
{
    for (DWVodVideoModel * videoModel in playInfosArray) {

        if (!videoModel) {
            //某个视频数据获取失败
            continue;
        }
        
        if (videoModel.authorize && !videoModel.authorize.enable) {
            //授权验证未通过,无法下载
            continue;
        }
        
        //这里根据自身业务逻辑进行调整, 默认全部下载首个媒体数据
        DWVideoQualityModel * qualityModel = videoModel.videoQualities.firstObject;
        if (!qualityModel) {
            qualityModel = videoModel.radioQualities.firstObject;
        }
        
        DWDownloadSessionManager * manager = [DWDownloadSessionManager manager];
        //验证当前任务是否已经在下载队列中
        if ([manager checkLocalResourceWithVideoId:videoModel.videoId WithQuality:qualityModel.quality]) {
            continue;
        }
        
        //获取视频图片地址,保存
        NSString * imageUrl = @"icon_placeholder.png";
        NSString * title = @"";
        for (DWVodModel * vodModel in self.vidoeList) {
            if ([vodModel.videoId isEqualToString:videoModel.videoId]) {
                imageUrl = vodModel.imageUrl;
                title = vodModel.title;
                break;
            }
        }
        
        DWDownloadModel * model = [DWDownloadSessionManager createDownloadModel:videoModel Quality:qualityModel.quality AndOthersInfo:@{@"imageUrl":imageUrl,@"title":title}];
        
        if (!model) {
            [@"DownloadModel创建失败,请检查参数" showAlert];
            continue;
        }
        
        [manager startWithDownloadModel:model];
        
    }
    
    [[NSString stringWithFormat:@"已开始下载%lu个视频",(unsigned long)playInfosArray.count] showAlert];
}
Han Ruisong's avatar
Han Ruisong committed
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
    
-(void)vodPlayBottomViewCancelButtonAction
{
    self.cellStyle = DWVodPlayTableViewCellStyleDefault;
    [self.listTableView reloadData];
    
    //清空选中数据
    for (DWVodModel * vodModel in self.vidoeList) {
        vodModel.isSelect = NO;
    }
}

#pragma mark - init
-(void)initParams
{
    self.cellStyle = DWVodPlayTableViewCellStyleDefault;
Hanruisong's avatar
Hanruisong committed
598
    self.isLock = NO;
Han Ruisong's avatar
Han Ruisong committed
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
}

-(void)initUI
{
    CGSize viewSize = CGSizeZero;
    if (@available(iOS 11.0, *)) {
        CGFloat a =  [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom;
        if (a > 0) {
            viewSize = CGSizeMake(ScreenWidth, ScaleHeight(ScreenWidth, 375 / 211.0) + 64);
        }else{
            viewSize = CGSizeMake(ScreenWidth, ScaleHeight(ScreenWidth, 375 / 211.0));
        }
    } else {
        viewSize = CGSizeMake(ScreenWidth, ScaleHeight(ScreenWidth, 375 / 211.0));
    }
    self.playerViewSize = viewSize;
    
Han Ruisong's avatar
Han Ruisong committed
616
617
618
619
620
621
622
623
624
625
626
    if (DWAPPDELEGATE.vodPlayerView) {
        self.playerView = DWAPPDELEGATE.vodPlayerView;
        //选集,要在退出小窗之前设置,否则选集列表会有显示问题
        self.playerView.selectionList = self.vidoeList;
        [self.playerView quitWindowsModel];
    }else{
        self.playerView = [[DWVodPlayerView alloc]init];
        //选集
        self.playerView.selectionList = self.vidoeList;
    }
    
Han Ruisong's avatar
Han Ruisong committed
627
628
    self.playerView.delegate = self;
    [self.view addSubview:self.playerView];
Han Ruisong's avatar
Han Ruisong committed
629
    [_playerView mas_remakeConstraints:^(MASConstraintMaker *make) {
Han Ruisong's avatar
Han Ruisong committed
630
631
632
633
634
635
636
637
638
639
640
641
        make.top.and.left.equalTo(@0);
        make.width.equalTo(@(self.playerViewSize.width));
        make.height.equalTo(@(self.playerViewSize.height));
    }];
    
    self.adShowView = [[DWAdShouView alloc]init];
    self.adShowView.hidden = YES;
    self.adShowView.delegate = self;
    [self.view addSubview:self.adShowView];
    [_adShowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.and.left.equalTo(@0);
        make.width.equalTo(@(self.playerViewSize.width));
Hanruisong's avatar
Hanruisong committed
642
        make.height.equalTo(@(self.playerViewSize.height - 40));
Han Ruisong's avatar
Han Ruisong committed
643
644
645
646
647
648
    }];
    
    self.listTableView = [[UITableView alloc]init];
    self.listTableView.delegate = self;
    self.listTableView.dataSource = self;
    self.listTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Han Ruisong's avatar
Han Ruisong committed
649
650

    self.listTableView.backgroundColor = self.view.backgroundColor;
Han Ruisong's avatar
Han Ruisong committed
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
    [self.view addSubview:self.listTableView];
    [_listTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(@0);
        make.top.equalTo(self.playerView.mas_bottom);
        make.bottom.equalTo(@(-15 - 40 - 15));
    }];
    
    UIView * headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 15 + 14 + 2.5)];
    self.listTableView.tableHeaderView = headerView;
    UILabel * headerTsLabel = [[UILabel alloc]init];
    headerTsLabel.text = @"课程目录";
    headerTsLabel.font = TitleFont(14);
    headerTsLabel.textColor = TitleColor_51;
    headerTsLabel.textAlignment = NSTextAlignmentLeft;
    [headerView addSubview:headerTsLabel];
    [headerTsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@10);
        make.top.equalTo(@15);
        make.width.equalTo(@(ScreenWidth - 20));
        make.height.equalTo(@14);
    }];
    
    self.bottomView = [[DWVodPlayBottomView alloc]init];
    self.bottomView.delegate = self;
    [self.view addSubview:self.bottomView];
    [_bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.listTableView.mas_bottom);
        make.bottom.equalTo(@0);
        make.left.and.right.equalTo(@0);
    }];
Han Ruisong's avatar
Han Ruisong committed
681
682
683
684
    
    if (self.landScape) {
        [self screenOrientationDidChange:YES];
    }
Han Ruisong's avatar
Han Ruisong committed
685
686
687
688
}

-(BOOL)shouldAutorotate
{
Hanruisong's avatar
Hanruisong committed
689
690
    return !self.isLock;
//    return YES;
Han Ruisong's avatar
Han Ruisong committed
691
692
693
694
695
696
697
698
699
700
701
702
703
}

/*
#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