// // ZFNormalViewController.m // ZFPlayer // // Created by 紫枫 on 2018/3/21. // Copyright © 2018年 紫枫. All rights reserved. // #import "ZFNormalViewController.h" #import #import #import #import "ZFNotAutoPlayViewController.h" #import #import #import #import "ZFUtilities.h" #import "PlayDetailBarView.h" #import "ZFPlayerControlView2.h" @import AVKit; static NSString *kVideoCover = @""; @interface ZFNormalViewController () @property (nonatomic, strong) ZFPlayerController *player; @property (nonatomic, strong) UIImageView *containerView; @property (nonatomic, strong) ZFPlayerControlView2 *controlView; @property (nonatomic, strong) UIButton *playBtn; @property (nonatomic, strong) UIButton *changeBtn; @property (nonatomic, strong) UIButton *nextBtn; @property (nonatomic, strong) UIButton *pipBtn; @property (nonatomic, strong) NSArray *assetURLs; @property (nonatomic, strong) AVPictureInPictureController *vc; @property (nonatomic, strong) UIScrollView *scrollView; @property (nonatomic, strong) UITableView *tableView; @property (nonatomic, strong) UITableView *tableView2; @property (nonatomic, strong) UITableView *tableView3; @property (nonatomic, assign) CGFloat sp; @property (nonatomic, assign) int episodes; @property (nonatomic, assign) int playQXDIndex; @property (nonatomic, strong) NSArray *reCommondMovies; @property (nonatomic, assign) float playProcess; @end @implementation ZFNormalViewController -(UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent; } - (void)viewDidLoad { [super viewDidLoad]; self.sp = 1.0; self.episodes = 1; self.fd_prefersNavigationBarHidden = true; self.view.backgroundColor = [UIColor blackColor]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewVC)]; [self.view addSubview:self.containerView]; [self.containerView addSubview:self.playBtn]; [self.view addSubview:self.changeBtn]; [self.view addSubview:self.nextBtn]; [self.view addSubview:self.pipBtn]; [self setupPlayer]; self.reCommondMovies = @[]; [self setupui]; // [self requestRecommondMovies]; [self requestWatch]; [self.controlView.bottomPgrogress addObserver:self forKeyPath:@"value" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil]; } -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ // NSLog(@"keyPath:%@,object:%@,change:%@,context:%@",keyPath,object,change,context); if([change[@"new"] floatValue] - self.playProcess >= 0.01){ self.playProcess = [change[@"new"] floatValue]; NSString * vid = [NSString stringWithFormat:@"%d",[self.playData[@"simple_info"][@"vid"] intValue]]; NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"playProcessData"]; if(dic){ NSMutableDictionary *mdic = [NSMutableDictionary dictionary]; [mdic addEntriesFromDictionary:dic]; [mdic setValue:@([change[@"new"] floatValue]) forKey:vid]; [[NSUserDefaults standardUserDefaults] setValue:mdic forKey:@"playProcessData"]; NSLog(@"更新进度成功"); }else{ NSMutableDictionary *mdic = [NSMutableDictionary dictionary]; [mdic setValue:@([change[@"new"] floatValue]) forKey:vid]; [[NSUserDefaults standardUserDefaults] setValue:mdic forKey:@"playProcessData"]; NSLog(@"更新进度成功"); } } } -(void)dealloc{ [self.controlView.bottomPgrogress removeObserver:self forKeyPath:@"value"]; NSLog(@"zf dealloc"); } -(void)requestWatch{ @zf_weakify(self); [RequestTool post:@"watch/watchRequest" params:@{@"episodes":@(self.episodes),@"vid":@(self.vid)} success:^(id responseObject) { @zf_strongify(self); NSLog(@"watch/watchRequest-%@",responseObject); if([responseObject[@"code"] intValue] == 0){ self.playData = [responseObject[@"data"] mutableCopy]; //添加历史 [UserModel addHistoryPlay:self.playData]; //获取进度 NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"processPlayVid"]; NSString * vid = [NSString stringWithFormat:@"%d",[self.playData[@"simple_info"][@"vid"] intValue]] ; if(dic[vid]){ self.playProcess = [dic[vid] floatValue]; }else{ self.playProcess = 0.0; } NSArray *arr = self.playData[@"video_urls"]; if(![arr isKindOfClass:[NSArray class]] || arr.count == 0){ NSString *toast = responseObject[@"msg"]; if(![toast isKindOfClass:[NSString class]] || toast.length == 0){ toast = @"暂无可播放资源"; } [MBProgressHUD showMessage:toast]; [self.player stop]; self->_assetURLs = @[]; [self.controlView resetControlView]; NSLog(@"数据异常"); return; } if(arr.count<=self.playQXDIndex){ if(arr.count>0){ self->_assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][0]]]; self.playQXDIndex = 0; }else{ NSLog(@"数据异常"); return; } }else{ self->_assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][self.playQXDIndex]]]; } self.player.assetURLs = self.assetURLs; //测试代码 // NSString *URLString = @"https://www.apple.com.cn/105/media/cn/airpods-pro/2022/d2deeb8e-83eb-48ea-9721-f567cf0fffa8/films/under-the-spell/airpods-pro-under-the-spell-tpl-cn-2022_16x9.m3u8"; // self.player.assetURL = [NSURL URLWithString:URLString]; [self.player playTheIndex:0]; //self.playData[@"simple_info"][@"horizontal_cover_url"] [self.controlView showTitle:[NSString stringWithFormat:@"%@ 第%d集",self.playData[@"simple_info"][@"ch_name"],self.episodes] coverURLString:@"" fullScreenMode:ZFFullScreenModeAutomatic]; [self.tableView reloadData]; if(arr.count==1){ self.controlView.landScapeControlView.pArr = @[@[@"480P",@"标清"]]; }else if(arr.count == 2){ self.controlView.landScapeControlView.pArr = @[@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]]; }else if(arr.count == 3){ self.controlView.landScapeControlView.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]]; } if(self.playQXDIndex == 0){ self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 1; }else if(self.playQXDIndex == 1){ self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 2; }else if(self.playQXDIndex == 2){ self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 3; } // self.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]]; [self requestRecommondMovies]; } } failure:^(NSError *error) {}]; } -(void)requestRecommondMovies{ int vid = [self.playData[@"simple_info"][@"vid"] intValue]; @zf_weakify(self); [RequestTool post:@"watch/getSameClassMovies" params:@{@"page":@{@"page":@(1),@"pageSize":@(9)},@"vid":@(vid)} success:^(id responseObject) { @zf_strongify(self); NSLog(@"watch/getSameClassMovies-%@",responseObject); if([responseObject[@"code"] intValue] == 0){ NSLog(@"%@",responseObject); id list = responseObject[@"data"][@"list"]; if([list isKindOfClass:[NSArray class]]){ self.reCommondMovies = list; }else{ self.reCommondMovies = @[]; } [self.tableView reloadData]; } } failure:^(NSError *error) {}]; } -(void)setupui{ PlayDetailBarView *pdb =[PlayDetailBarView new]; [self.view addSubview:pdb]; [pdb mas_makeConstraints:^(MASConstraintMaker *make) { make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 46)); make.left.equalTo(self.view); make.top.equalTo(self.containerView.mas_bottom); }]; [self.view addSubview:self.scrollView]; [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(pdb.mas_bottom); make.left.equalTo(self.view); make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16)); make.width.mas_equalTo(@(SCREEN_WIDTH)); }]; [self.scrollView addSubview:self.tableView]; [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(pdb.mas_bottom); make.left.equalTo(self.view); make.width.mas_equalTo(@(SCREEN_WIDTH)); make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16)); }]; // [self.scrollView addSubview:self.tableView2]; // [self.tableView2 mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(pdb.mas_bottom); // make.left.equalTo(self.view).offset(SCREEN_WIDTH); // make.width.mas_equalTo(@(SCREEN_WIDTH)); // make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16)); // }]; // [self.scrollView addSubview:self.tableView3]; // [self.tableView3 mas_makeConstraints:^(MASConstraintMaker *make) { // make.top.equalTo(pdb.mas_bottom); // make.left.equalTo(self.view).offset(SCREEN_WIDTH*2); // make.width.mas_equalTo(@(SCREEN_WIDTH)); // make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16)); // }]; self.scrollView.contentSize = CGSizeMake(0, 0); } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.player.viewControllerDisappear = NO; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.player.viewControllerDisappear = YES; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; CGFloat x = 0; CGFloat y = safetop; //CGRectGetMaxY(self.navigationController.navigationBar.frame); CGFloat w = CGRectGetWidth(self.view.frame); CGFloat h = w*9/16; self.containerView.frame = CGRectMake(x, y, w, h); // w = 44; // h = w; // x = (CGRectGetWidth(self.containerView.frame)-w)/2; // y = (CGRectGetHeight(self.containerView.frame)-h)/2; // self.playBtn.frame = CGRectMake(x, y, w, h); // // w = 100; // h = 30; // x = (CGRectGetWidth(self.view.frame)-w)/2; // y = CGRectGetMaxY(self.containerView.frame)+50; // self.changeBtn.frame = CGRectMake(x, y, w, h); // // w = 100; // h = 30; // x = (CGRectGetWidth(self.view.frame)-w)/2; // y = CGRectGetMaxY(self.changeBtn.frame)+50; // self.nextBtn.frame = CGRectMake(x, y, w, h); // // // w = 100; // h = 30; // x = (CGRectGetWidth(self.view.frame)-w)/2; // y = CGRectGetMaxY(self.nextBtn.frame)+50; // self.pipBtn.frame = CGRectMake(x, y, w, h); } - (void)setupPlayer { ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init]; // ZFIJKPlayerManager *playerManager = [[ZFIJKPlayerManager alloc] init]; playerManager.shouldAutoPlay = YES; /// 播放器相关 self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView]; self.player.controlView = self.controlView; /// 设置退到后台继续播放 self.player.pauseWhenAppResignActive = YES; // self.player.resumePlayRecord = YES; @zf_weakify(self) self.player.orientationDidChanged = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) { /* // 使用YYTextView转屏失败 for (UIWindow *window in [UIApplication sharedApplication].windows) { if ([window isKindOfClass:NSClassFromString(@"YYTextEffectWindow")]) { window.hidden = isFullScreen; } } */ }; /// 播放完成 self.player.playerDidToEnd = ^(id _Nonnull asset) { @zf_strongify(self) if (!self.player.isLastAssetURL) { [self.player playTheNext]; NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex]; [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape]; } else { [self.player stop]; } }; //修改播放速度 self.player.playerPlayStateChanged = ^(id _Nonnull asset, ZFPlayerPlaybackState playState) { @zf_strongify(self) if(playState == ZFPlayerPlayStatePlaying){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager; manager.rate = self.sp; }); } }; } - (void)picBtnClick { /// 配置画中画 ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager; AVPictureInPictureController *vc = [[AVPictureInPictureController alloc] initWithPlayerLayer:manager.avPlayerLayer]; self.vc = vc; ///要有延迟 否则可能开启不成功 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0*NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self.vc startPictureInPicture]; }); } - (void)changeVideo:(UIButton *)sender { NSString *URLString = @"https://www.apple.com.cn/105/media/cn/airpods-pro/2022/d2deeb8e-83eb-48ea-9721-f567cf0fffa8/films/under-the-spell/airpods-pro-under-the-spell-tpl-cn-2022_16x9.m3u8"; self.player.assetURL = [NSURL URLWithString:URLString]; [self.controlView showTitle:@"AirPods" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic]; } - (void)playClick:(UIButton *)sender { [self.player playTheIndex:0]; [self.controlView showTitle:@"视频标题" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic]; } - (void)nextClick:(UIButton *)sender { if (!self.player.isLastAssetURL) { [self.player playTheNext]; NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex]; [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic]; } else { NSLog(@"最后一个视频了"); } } - (void)pushNewVC { ZFNotAutoPlayViewController *vc = [[ZFNotAutoPlayViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ __weak typeof (self) weakSelf = self; if(indexPath.row == 0){ playercell1 * cell = [playercell1 cellWithTableView:tableView]; cell.playData = self.playData; return cell; }else if(indexPath.row == 1){ playercell2 * cell = [playercell2 cellWithTableView:tableView]; cell.playData =self.playData; cell.changPlayBlock = ^(int index) { weakSelf.episodes = index; [weakSelf requestWatch]; }; return cell; }else if(indexPath.row == 2){ playercell3 * cell = [playercell3 cellWithTableView:tableView]; return cell; }else { playercell4 * cell = [playercell4 cellWithTableView:tableView]; if((indexPath.row-3)*3 + 3>self.reCommondMovies.count){ cell.reCommondMovies = [self.reCommondMovies subarrayWithRange:NSMakeRange((indexPath.row-3)*3, self.reCommondMovies.count-(indexPath.row-3)*3)]; }else{ cell.reCommondMovies = [self.reCommondMovies subarrayWithRange:NSMakeRange((indexPath.row-3)*3, 3)]; } cell.tapBlock = ^(int index) { weakSelf.episodes = 1; weakSelf.vid = index; [weakSelf requestWatch]; }; return cell; } } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ if(self.reCommondMovies.count%3==0){ return 3+self.reCommondMovies.count/3; }else{ return 3+self.reCommondMovies.count/3+1; } } -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ if(indexPath.row == 0){ return 80; }else if(indexPath.row == 1){ return 122; }else if(indexPath.row == 2){ return 46; }else { return 198; } } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ } -(UIScrollView *)scrollView{ if(!_scrollView){ _scrollView =[UIScrollView new]; _scrollView.showsVerticalScrollIndicator = false; _scrollView.showsHorizontalScrollIndicator = false; _scrollView.pagingEnabled = true; } return _scrollView; } -(UITableView *)tableView{ if(!_tableView){ _tableView =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; _tableView.delegate = self; _tableView.dataSource = self; _tableView.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView.showsVerticalScrollIndicator = false; _tableView.showsHorizontalScrollIndicator = false; _tableView.backgroundColor = rgba(18, 23, 41, 1); // _tableView.backgroundColor = [UIColor redColor]; if (@available(iOS 11, *)) { _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _tableView.estimatedRowHeight = 0; _tableView.estimatedSectionFooterHeight = 0; _tableView.estimatedSectionHeaderHeight = 0; UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow; UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets; CGFloat topSafeArea = safeAreaInsets.top; _tableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, 0, 0); // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0); } #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this if (@available(iOS 15.0, *)) { _tableView.sectionHeaderTopPadding = 0; } #endif } return _tableView; } -(UITableView *)tableView2{ if(!_tableView2){ _tableView2 =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; _tableView2.delegate = self; _tableView2.dataSource = self; _tableView2.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView2.showsVerticalScrollIndicator = false; _tableView2.showsHorizontalScrollIndicator = false; _tableView2.backgroundColor = rgba(18, 23, 41, 1); // _tableView.backgroundColor = [UIColor redColor]; if (@available(iOS 11, *)) { _tableView2.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _tableView2.estimatedRowHeight = 0; _tableView2.estimatedSectionFooterHeight = 0; _tableView2.estimatedSectionHeaderHeight = 0; UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow; UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets; CGFloat topSafeArea = safeAreaInsets.top; _tableView2.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0); // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0); } #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this if (@available(iOS 15.0, *)) { _tableView2.sectionHeaderTopPadding = 0; } #endif } return _tableView2; } -(UITableView *)tableView3{ if(!_tableView3){ _tableView3 =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped]; _tableView3.delegate = self; _tableView3.dataSource = self; _tableView3.separatorStyle = UITableViewCellSeparatorStyleNone; _tableView3.showsVerticalScrollIndicator = false; _tableView3.showsHorizontalScrollIndicator = false; _tableView3.backgroundColor = rgba(18, 23, 41, 1); // _tableView.backgroundColor = [UIColor redColor]; if (@available(iOS 11, *)) { _tableView3.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; _tableView3.estimatedRowHeight = 0; _tableView3.estimatedSectionFooterHeight = 0; _tableView3.estimatedSectionHeaderHeight = 0; UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow; UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets; CGFloat topSafeArea = safeAreaInsets.top; _tableView3.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0); // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0); } #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this if (@available(iOS 15.0, *)) { _tableView3.sectionHeaderTopPadding = 0; } #endif } return _tableView3; } //- (UIStatusBarStyle)preferredStatusBarStyle { // return UIStatusBarStyleDefault; //} - (BOOL)prefersStatusBarHidden { return NO; } - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { return UIStatusBarAnimationNone; } - (BOOL)shouldAutorotate { return NO; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (ZFPlayerControlView2 *)controlView { if (!_controlView) { _controlView = [ZFPlayerControlView2 new]; _controlView.fastViewAnimated = YES; _controlView.effectViewShow = NO; _controlView.autoHiddenTimeInterval = 5; _controlView.autoFadeTimeInterval = 0.5; _controlView.prepareShowLoading = YES; _controlView.prepareShowControlView = NO; _controlView.showCustomStatusBar = YES; __weak typeof (self) weakSelf = self; _controlView.speedBtnClickCallback = ^(CGFloat sp){ weakSelf.sp = sp; ZFAVPlayerManager *manager = (ZFAVPlayerManager *)weakSelf.player.currentPlayerManager; manager.rate = sp; }; _controlView.clickBackBlock = ^{ [weakSelf.navigationController popViewControllerAnimated:true]; }; _controlView.nextBtnClickCallback = ^{ int total = [weakSelf.playData[@"simple_info"][@"total_episodes"] intValue]; int current = weakSelf.episodes; if(current 0){ weakSelf.player.assetURL = [NSURL URLWithString:URLString]; //weakSelf.playData[@"simple_info"][@"horizontal_cover_url"] [weakSelf.controlView showTitle:weakSelf.playData[@"simple_info"][@"ch_name"] coverURLString:@"" fullScreenMode:ZFFullScreenModeAutomatic]; [weakSelf.player seekToTime:second completionHandler:^(BOOL finished) { }]; } }; } return _controlView; } - (UIImageView *)containerView { if (!_containerView) { _containerView = [UIImageView new]; [_containerView setImageWithURLString:kVideoCover placeholder:[ZFUtilities imageWithColor:[UIColor blackColor] size:CGSizeMake(1, 1)]]; } return _containerView; } - (UIButton *)playBtn { if (!_playBtn) { _playBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal]; [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside]; } return _playBtn; } - (UIButton *)changeBtn { if (!_changeBtn) { _changeBtn = [UIButton buttonWithType:UIButtonTypeSystem]; [_changeBtn setTitle:@"Change video" forState:UIControlStateNormal]; [_changeBtn addTarget:self action:@selector(changeVideo:) forControlEvents:UIControlEventTouchUpInside]; } return _changeBtn; } - (UIButton *)nextBtn { if (!_nextBtn) { _nextBtn = [UIButton buttonWithType:UIButtonTypeSystem]; [_nextBtn setTitle:@"Next" forState:UIControlStateNormal]; [_nextBtn addTarget:self action:@selector(nextClick:) forControlEvents:UIControlEventTouchUpInside]; } return _nextBtn; } - (UIButton *)pipBtn { if (!_pipBtn) { _pipBtn = [UIButton buttonWithType:UIButtonTypeSystem]; [_pipBtn setTitle:@"开启画中画" forState:UIControlStateNormal]; [_pipBtn addTarget:self action:@selector(picBtnClick) forControlEvents:UIControlEventTouchUpInside]; } return _pipBtn; } - (NSArray *)assetURLs { if (!_assetURLs) { _assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][self.playQXDIndex]]]; } return _assetURLs; } //[NSURL URLWithString:@"http://together-watch-mytest-bucket1.oss-cn-shanghai.aliyuncs.com/video%2Fuploads%2F1%2F1_1_480.mp4?Expires=1689755418&OSSAccessKeyId=LTAI5t8WGw2YFnQRRJ1oBNnb&Signature=mqlsqmxaOtRE065o1HXmu7mp4tw%3D"],[NSURL URLWithString:@"https://www.apple.com/105/media/us/iphone-x/2017/01df5b43-28e4-4848-bf20-490c34a926a7/films/feature/iphone-x-feature-tpl-cc-us-20170912_1280x720h.mp4"], // [NSURL URLWithString:@"https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4"], // [NSURL URLWithString:@"https://www.apple.com/105/media/us/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/peter/mac-peter-tpl-cc-us-2018_1280x720h.mp4"], // [NSURL URLWithString:@"https://www.apple.com/105/media/us/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/grimes/mac-grimes-tpl-cc-us-2018_1280x720h.mp4"], // [NSURL URLWithString:@"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7194236f31b2e1e3da0fe06cfed4ba2b.mp4"], // [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"], // [NSURL URLWithString:@"http://vjs.zencdn.net/v/oceans.mp4"], // [NSURL URLWithString:@"https://media.w3.org/2010/05/sintel/trailer.mp4"], // [NSURL URLWithString:@"http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4"], // [NSURL URLWithString:@"https://sample-videos.com/video123/mp4/480/big_buck_bunny_480p_2mb.mp4"] @end @interface playercell1() @end @implementation playercell1 + (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *identifier = @"playercell1"; playercell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[playercell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } return cell; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self creatView]; } return self; } -(void)addCollectAct{ int vid = [self.playData[@"simple_info"][@"vid"] intValue]; UIButton *btn = [self.contentView viewWithTag:150]; if([UserModel collectContainVid:vid]){ [UserModel delCollect:self.playData[@"simple_info"]]; [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal]; [btn setTitle:@" 收藏" forState:UIControlStateNormal]; }else{ [UserModel addCollect:self.playData[@"simple_info"]]; [btn setTitle:@"已收藏" forState:UIControlStateNormal]; [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal]; } } -(void)setPlayData:(NSDictionary *)playData { _playData = playData; UILabel *lab = [self.contentView viewWithTag:100]; lab.text = playData[@"simple_info"][@"ch_name"]; UILabel *lab2 = [self.contentView viewWithTag:101]; lab2.text = [NSString stringWithFormat:@"%.1f分",[playData[@"simple_info"][@"score"] floatValue]]; UILabel *lab3 = [self.contentView viewWithTag:102]; NSArray *arr = playData[@"simple_info"][@"class_list"]; NSString *t3=@""; for(int i=0;i0){ lab3.text = [t3 substringToIndex:t3.length-1]; } int vid = [playData[@"simple_info"][@"vid"] intValue]; UIButton *btn = [self.contentView viewWithTag:150]; if([UserModel collectContainVid:vid]){ [btn setTitle:@"已收藏" forState:UIControlStateNormal]; [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal]; }else{ [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal]; [btn setTitle:@" 收藏" forState:UIControlStateNormal]; } } -(void)creatView{ self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; UILabel *lab = [UILabel new]; lab.text = @"勇敢者的游戏"; lab.tag = 100; lab.textColor = rgba(255, 255, 255, 1); lab.font = [UIFont boldSystemFontOfSize:20]; [self.contentView addSubview:lab]; [lab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(16); make.left.equalTo(self.contentView).offset(12); }]; UILabel *lab2 = [UILabel new]; lab2.text = @"9.6分"; lab2.tag = 101; lab2.textColor = rgba(255, 212, 0, 1); lab2.font = [UIFont systemFontOfSize:12]; lab2.backgroundColor = rgba(247, 187, 1, 0.2); lab2.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:lab2]; [lab2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(lab.mas_bottom).offset(14); make.left.equalTo(self.contentView).offset(12); make.size.mas_equalTo(CGSizeMake(50, 24)); }]; UILabel *lab3 = [UILabel new]; lab3.tag = 102; lab3.text = @"悬疑/罪案/动作"; lab3.textColor = rgba(255, 255, 255, 0.4); lab3.font = [UIFont systemFontOfSize:12]; [self.contentView addSubview:lab3]; [lab3 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(lab2); make.left.equalTo(lab2.mas_right).offset(6); }]; UIButton *btn = [UIButton new]; btn.tag = 150; [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal]; [btn setTitle:@" 收藏" forState:UIControlStateNormal]; btn.titleLabel.font = [UIFont systemFontOfSize:12]; [btn setTitleColor:rgba(255, 255, 255, 0.4) forState:UIControlStateNormal]; [btn setBackgroundColor:rgba(255, 255, 255, 0.03)]; [btn addTarget:self action:@selector(addCollectAct) forControlEvents:UIControlEventTouchUpInside]; [self.contentView addSubview:btn]; [btn mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(lab2); make.right.equalTo(self.contentView).offset(-28); make.size.mas_equalTo(CGSizeMake(74, 30)); }]; lab2.layer.cornerRadius = 8; lab2.layer.masksToBounds = true; btn.layer.cornerRadius = 8; btn.layer.masksToBounds = true; } @end @interface playercell2() @property(nonatomic,strong)UICollectionView *collect; @property(nonatomic,assign)int count; @end @implementation playercell2 + (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *identifier = @"playercell2"; playercell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[playercell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } return cell; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self creatView]; } return self; } -(void)setPlayData:(NSDictionary *)playData{ _playData = playData; self.count = [playData[@"simple_info"][@"total_episodes"] intValue]; [self.collect reloadData]; } -(void)creatView{ self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; UILabel *lab = [UILabel new]; lab.text = @"选集"; lab.textColor = rgba(255, 255, 255, 1); lab.font = [UIFont boldSystemFontOfSize:16]; [self.contentView addSubview:lab]; [lab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(24); make.left.equalTo(self.contentView).offset(12); }]; UILabel *lab2 = [UILabel new]; // lab2.text = @"每周二、周三凌晨更新"; lab2.textColor = rgba(255, 255, 255, 0.4); lab2.font = [UIFont systemFontOfSize:12]; lab2.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:lab2]; [lab2 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(lab); make.left.equalTo(lab.mas_right).offset(8); }]; UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-12, 64)]; bg.backgroundColor = rgba(255, 255, 255, 0.03); [self.contentView addSubview:bg]; [bg mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(12); make.top.equalTo(lab.mas_bottom).offset(12); make.right.equalTo(self.contentView); make.height.mas_equalTo(@64); // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-12, 64)); }]; [self.contentView addSubview:self.collect]; [self.collect mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(12); make.top.equalTo(lab.mas_bottom).offset(12); make.right.equalTo(self.contentView); make.height.mas_equalTo(@64); // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-12, 64)); }]; // 创建圆角图层 UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bg.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(8, 8)]; CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.path = path.CGPath; bg.layer.mask = maskLayer; } -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ playItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([playItemCell class]) forIndexPath:indexPath]; cell.index = indexPath.row+1; if(indexPath.row == [self.playData[@"episodes"] intValue]-1){ cell.isSel = true; }else{ cell.isSel = false; } return cell; } -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ if(self.changPlayBlock){ self.changPlayBlock((int)indexPath.row+1); } } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return [self.playData[@"simple_info"][@"total_episodes"] intValue]; } - (UICollectionView *)collect { if (!_collect) { UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; layout.itemSize = CGSizeMake(48, 48); layout.minimumLineSpacing = 8; //跟滚动方向相同的间距 // layout.minimumInteritemSpacing = 8; //跟滚动方向垂直的间距 layout.scrollDirection = UICollectionViewScrollDirectionHorizontal; _collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH-12, 64) collectionViewLayout:layout]; _collect.contentInset = UIEdgeInsetsMake(8, 12, 8, 12); //注册cell [_collect registerClass:[playItemCell class] forCellWithReuseIdentifier:@"playItemCell"]; // [_collect registerClass:[SearchItemCell class] forCellWithReuseIdentifier:@"SearchItemCell"]; // [_collect registerClass:[FoundCell class] forCellWithReuseIdentifier:@"FoundCell"]; // [_collect registerClass:[HotSearchCell class] forCellWithReuseIdentifier:@"HotSearchCell"]; _collect.dataSource = self; _collect.delegate = self; _collect.backgroundColor = [UIColor clearColor]; _collect.showsVerticalScrollIndicator = false; _collect.showsHorizontalScrollIndicator = false; } return _collect; } @end @interface playItemCell() @property(nonatomic,strong)UILabel *lab; @property(nonatomic,strong)UIImageView *iv; @end @implementation playItemCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setUp]; } return self; } -(void)setIndex:(NSInteger)index{ _index = index; self.lab.text = [NSString stringWithFormat:@"%ld",(long)index]; } - (void)setIsSel:(BOOL)isSel{ _isSel = isSel; if(isSel){ self.lab.backgroundColor = rgba(247, 187, 1, 0.2); self.lab.textColor = rgba(255, 212, 0, 1); self.iv.hidden = false; }else{ self.lab.backgroundColor = rgba(18, 23, 41, 1); self.lab.textColor = rgba(255, 255, 255, 0.4); self.iv.hidden = true; } } - (void)setUp { self.backgroundColor = [UIColor clearColor]; //选中背景 rgba(247, 187, 1, 0.2) UILabel *lab = [UILabel new]; self.lab= lab; // lab.text = @"选集"; lab.textColor = rgba(255, 255, 255, 0.4); lab.font = [UIFont boldSystemFontOfSize:16]; lab.textAlignment = NSTextAlignmentCenter; [self.contentView addSubview:lab]; [lab mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.contentView); }]; UIImageView *iv = [UIImageView new]; iv.image = [UIImage imageNamed:@"Group 427319579"]; self.iv = iv; [self.contentView addSubview:iv]; [iv mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(6); make.bottom.equalTo(self.contentView).offset(-5); make.size.mas_equalTo(CGSizeMake(10, 10)); }]; self.lab.layer.cornerRadius = 8; self.lab.layer.masksToBounds = true; } @end @interface playercell3 () @end @implementation playercell3 + (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *identifier = @"playercell3"; playercell3 *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[playercell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } return cell; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self creatView]; } return self; } -(void)creatView{ self.selectionStyle = UITableViewCellSelectionStyleNone; self.backgroundColor = [UIColor clearColor]; UILabel *lab = [UILabel new]; lab.text = @"猜你喜欢"; lab.textColor = rgba(255, 255, 255, 1); lab.font = [UIFont boldSystemFontOfSize:16]; [self.contentView addSubview:lab]; [lab mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.contentView).offset(24); make.left.equalTo(self.contentView).offset(12); }]; UIImageView *iv = [UIImageView new]; // iv.image = [UIImage imageNamed:@"Frame 9391"]; [self.contentView addSubview:iv]; [iv mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(lab); make.right.equalTo(self.contentView).offset(-12); make.size.mas_equalTo(CGSizeMake(12, 12)); }]; UILabel *lab2 = [UILabel new]; // lab2.text = @"查看更多"; lab2.textColor = rgba(255, 255, 255, 0.4); lab2.font = [UIFont systemFontOfSize:12]; [self.contentView addSubview:lab2]; [lab2 mas_makeConstraints:^(MASConstraintMaker *make) { make.centerY.equalTo(lab); make.right.equalTo(iv.mas_left); }]; } @end @interface playercell4 () @end @implementation playercell4 + (instancetype)cellWithTableView:(UITableView *)tableView{ static NSString *identifier = @"playercell4"; playercell4 *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (cell == nil) { cell = [[playercell4 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } return cell; } - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { [self creatView]; } return self; } -(void)setReCommondMovies:(NSArray *)reCommondMovies{ _reCommondMovies = reCommondMovies; for(int i=0;i<3;i++){ if(i