ZFNormalViewController.m 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  1. //
  2. // ZFNormalViewController.m
  3. // ZFPlayer
  4. //
  5. // Created by 紫枫 on 2018/3/21.
  6. // Copyright © 2018年 紫枫. All rights reserved.
  7. //
  8. #import "ZFNormalViewController.h"
  9. #import <ZFPlayer/ZFAVPlayerManager.h>
  10. #import <ZFPlayer/ZFIJKPlayerManager.h>
  11. #import <ZFPlayer/ZFPlayerControlView.h>
  12. #import "ZFNotAutoPlayViewController.h"
  13. #import <ZFPlayer/UIView+ZFFrame.h>
  14. #import <ZFPlayer/UIImageView+ZFCache.h>
  15. #import <ZFPlayer/ZFPlayerConst.h>
  16. #import "ZFUtilities.h"
  17. #import "PlayDetailBarView.h"
  18. #import "ZFPlayerControlView2.h"
  19. @import AVKit;
  20. static NSString *kVideoCover = @"";
  21. @interface ZFNormalViewController ()<UITableViewDelegate,UITableViewDataSource>
  22. @property (nonatomic, strong) ZFPlayerController *player;
  23. @property (nonatomic, strong) UIImageView *containerView;
  24. @property (nonatomic, strong) ZFPlayerControlView2 *controlView;
  25. @property (nonatomic, strong) UIButton *playBtn;
  26. @property (nonatomic, strong) UIButton *changeBtn;
  27. @property (nonatomic, strong) UIButton *nextBtn;
  28. @property (nonatomic, strong) UIButton *pipBtn;
  29. @property (nonatomic, strong) NSArray <NSURL *>*assetURLs;
  30. @property (nonatomic, strong) AVPictureInPictureController *vc;
  31. @property (nonatomic, strong) UIScrollView *scrollView;
  32. @property (nonatomic, strong) UITableView *tableView;
  33. @property (nonatomic, strong) UITableView *tableView2;
  34. @property (nonatomic, strong) UITableView *tableView3;
  35. @property (nonatomic, assign) CGFloat sp;
  36. @property (nonatomic, assign) int episodes;
  37. @property (nonatomic, assign) int playQXDIndex;
  38. @property (nonatomic, strong) NSArray *reCommondMovies;
  39. @property (nonatomic, assign) float playProcess;
  40. @end
  41. @implementation ZFNormalViewController
  42. -(UIStatusBarStyle)preferredStatusBarStyle{
  43. return UIStatusBarStyleLightContent;
  44. }
  45. - (void)viewDidLoad {
  46. [super viewDidLoad];
  47. self.sp = 1.0;
  48. self.episodes = 1;
  49. self.fd_prefersNavigationBarHidden = true;
  50. self.view.backgroundColor = [UIColor blackColor];
  51. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Push" style:UIBarButtonItemStylePlain target:self action:@selector(pushNewVC)];
  52. [self.view addSubview:self.containerView];
  53. [self.containerView addSubview:self.playBtn];
  54. [self.view addSubview:self.changeBtn];
  55. [self.view addSubview:self.nextBtn];
  56. [self.view addSubview:self.pipBtn];
  57. [self setupPlayer];
  58. self.reCommondMovies = @[];
  59. [self setupui];
  60. // [self requestRecommondMovies];
  61. [self requestWatch];
  62. [self.controlView.bottomPgrogress addObserver:self forKeyPath:@"value" options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) context:nil];
  63. }
  64. -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
  65. // NSLog(@"keyPath:%@,object:%@,change:%@,context:%@",keyPath,object,change,context);
  66. if([change[@"new"] floatValue] - self.playProcess >= 0.01){
  67. self.playProcess = [change[@"new"] floatValue];
  68. NSString * vid = [NSString stringWithFormat:@"%d",[self.playData[@"simple_info"][@"vid"] intValue]];
  69. NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"playProcessData"];
  70. if(dic){
  71. NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
  72. [mdic addEntriesFromDictionary:dic];
  73. [mdic setValue:@([change[@"new"] floatValue]) forKey:vid];
  74. [[NSUserDefaults standardUserDefaults] setValue:mdic forKey:@"playProcessData"];
  75. NSLog(@"更新进度成功");
  76. }else{
  77. NSMutableDictionary *mdic = [NSMutableDictionary dictionary];
  78. [mdic setValue:@([change[@"new"] floatValue]) forKey:vid];
  79. [[NSUserDefaults standardUserDefaults] setValue:mdic forKey:@"playProcessData"];
  80. NSLog(@"更新进度成功");
  81. }
  82. }
  83. }
  84. -(void)dealloc{
  85. [self.controlView.bottomPgrogress removeObserver:self forKeyPath:@"value"];
  86. NSLog(@"zf dealloc");
  87. }
  88. -(void)requestWatch{
  89. @zf_weakify(self);
  90. [RequestTool post:@"watch/watchRequest" params:@{@"episodes":@(self.episodes),@"vid":@(self.vid)} success:^(id responseObject) {
  91. @zf_strongify(self);
  92. NSLog(@"watch/watchRequest-%@",responseObject);
  93. if([responseObject[@"code"] intValue] == 0){
  94. self.playData = [responseObject[@"data"] mutableCopy];
  95. //添加历史
  96. [UserModel addHistoryPlay:self.playData];
  97. //获取进度
  98. NSDictionary *dic = [[NSUserDefaults standardUserDefaults] objectForKey:@"processPlayVid"];
  99. NSString * vid = [NSString stringWithFormat:@"%d",[self.playData[@"simple_info"][@"vid"] intValue]] ;
  100. if(dic[vid]){
  101. self.playProcess = [dic[vid] floatValue];
  102. }else{
  103. self.playProcess = 0.0;
  104. }
  105. NSArray *arr = self.playData[@"video_urls"];
  106. if(![arr isKindOfClass:[NSArray class]] || arr.count == 0){
  107. NSString *toast = responseObject[@"msg"];
  108. if(![toast isKindOfClass:[NSString class]] || toast.length == 0){
  109. toast = @"暂无可播放资源";
  110. }
  111. [MBProgressHUD showMessage:toast];
  112. [self.player stop];
  113. self->_assetURLs = @[];
  114. [self.controlView resetControlView];
  115. NSLog(@"数据异常");
  116. return;
  117. }
  118. if(arr.count<=self.playQXDIndex){
  119. if(arr.count>0){
  120. self->_assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][0]]];
  121. self.playQXDIndex = 0;
  122. }else{
  123. NSLog(@"数据异常");
  124. return;
  125. }
  126. }else{
  127. self->_assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][self.playQXDIndex]]];
  128. }
  129. self.player.assetURLs = self.assetURLs;
  130. //测试代码
  131. // 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";
  132. // self.player.assetURL = [NSURL URLWithString:URLString];
  133. [self.player playTheIndex:0];
  134. //self.playData[@"simple_info"][@"horizontal_cover_url"]
  135. [self.controlView showTitle:[NSString stringWithFormat:@"%@ 第%d集",self.playData[@"simple_info"][@"ch_name"],self.episodes] coverURLString:@"" fullScreenMode:ZFFullScreenModeAutomatic];
  136. [self.tableView reloadData];
  137. if(arr.count==1){
  138. self.controlView.landScapeControlView.pArr = @[@[@"480P",@"标清"]];
  139. }else if(arr.count == 2){
  140. self.controlView.landScapeControlView.pArr = @[@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
  141. }else if(arr.count == 3){
  142. self.controlView.landScapeControlView.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
  143. }
  144. if(self.playQXDIndex == 0){
  145. self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 1;
  146. }else if(self.playQXDIndex == 1){
  147. self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 2;
  148. }else if(self.playQXDIndex == 2){
  149. self.controlView.landScapeControlView.defaultPIndex = (int)arr.count - 3;
  150. }
  151. // self.pArr = @[@[@"1080P",@"超清 SDR"],@[@"720P",@"高清 SDR"],@[@"480P",@"标清"]];
  152. [self requestRecommondMovies];
  153. }
  154. } failure:^(NSError *error) {}];
  155. }
  156. -(void)requestRecommondMovies{
  157. int vid = [self.playData[@"simple_info"][@"vid"] intValue];
  158. @zf_weakify(self);
  159. [RequestTool post:@"watch/getSameClassMovies" params:@{@"page":@{@"page":@(1),@"pageSize":@(9)},@"vid":@(vid)} success:^(id responseObject) {
  160. @zf_strongify(self);
  161. NSLog(@"watch/getSameClassMovies-%@",responseObject);
  162. if([responseObject[@"code"] intValue] == 0){
  163. NSLog(@"%@",responseObject);
  164. id list = responseObject[@"data"][@"list"];
  165. if([list isKindOfClass:[NSArray class]]){
  166. self.reCommondMovies = list;
  167. }else{
  168. self.reCommondMovies = @[];
  169. }
  170. [self.tableView reloadData];
  171. }
  172. } failure:^(NSError *error) {}];
  173. }
  174. -(void)setupui{
  175. PlayDetailBarView *pdb =[PlayDetailBarView new];
  176. [self.view addSubview:pdb];
  177. [pdb mas_makeConstraints:^(MASConstraintMaker *make) {
  178. make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 46));
  179. make.left.equalTo(self.view);
  180. make.top.equalTo(self.containerView.mas_bottom);
  181. }];
  182. [self.view addSubview:self.scrollView];
  183. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  184. make.top.equalTo(pdb.mas_bottom);
  185. make.left.equalTo(self.view);
  186. make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
  187. make.width.mas_equalTo(@(SCREEN_WIDTH));
  188. }];
  189. [self.scrollView addSubview:self.tableView];
  190. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  191. make.top.equalTo(pdb.mas_bottom);
  192. make.left.equalTo(self.view);
  193. make.width.mas_equalTo(@(SCREEN_WIDTH));
  194. make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
  195. }];
  196. // [self.scrollView addSubview:self.tableView2];
  197. // [self.tableView2 mas_makeConstraints:^(MASConstraintMaker *make) {
  198. // make.top.equalTo(pdb.mas_bottom);
  199. // make.left.equalTo(self.view).offset(SCREEN_WIDTH);
  200. // make.width.mas_equalTo(@(SCREEN_WIDTH));
  201. // make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
  202. // }];
  203. // [self.scrollView addSubview:self.tableView3];
  204. // [self.tableView3 mas_makeConstraints:^(MASConstraintMaker *make) {
  205. // make.top.equalTo(pdb.mas_bottom);
  206. // make.left.equalTo(self.view).offset(SCREEN_WIDTH*2);
  207. // make.width.mas_equalTo(@(SCREEN_WIDTH));
  208. // make.height.mas_equalTo(@(kScreenHeight - 46 - safetop - SCREEN_WIDTH*9/16));
  209. // }];
  210. self.scrollView.contentSize = CGSizeMake(0, 0);
  211. }
  212. - (void)viewWillAppear:(BOOL)animated {
  213. [super viewWillAppear:animated];
  214. self.player.viewControllerDisappear = NO;
  215. }
  216. - (void)viewWillDisappear:(BOOL)animated {
  217. [super viewWillDisappear:animated];
  218. self.player.viewControllerDisappear = YES;
  219. }
  220. - (void)viewWillLayoutSubviews {
  221. [super viewWillLayoutSubviews];
  222. CGFloat x = 0;
  223. CGFloat y = safetop;
  224. //CGRectGetMaxY(self.navigationController.navigationBar.frame);
  225. CGFloat w = CGRectGetWidth(self.view.frame);
  226. CGFloat h = w*9/16;
  227. self.containerView.frame = CGRectMake(x, y, w, h);
  228. // w = 44;
  229. // h = w;
  230. // x = (CGRectGetWidth(self.containerView.frame)-w)/2;
  231. // y = (CGRectGetHeight(self.containerView.frame)-h)/2;
  232. // self.playBtn.frame = CGRectMake(x, y, w, h);
  233. //
  234. // w = 100;
  235. // h = 30;
  236. // x = (CGRectGetWidth(self.view.frame)-w)/2;
  237. // y = CGRectGetMaxY(self.containerView.frame)+50;
  238. // self.changeBtn.frame = CGRectMake(x, y, w, h);
  239. //
  240. // w = 100;
  241. // h = 30;
  242. // x = (CGRectGetWidth(self.view.frame)-w)/2;
  243. // y = CGRectGetMaxY(self.changeBtn.frame)+50;
  244. // self.nextBtn.frame = CGRectMake(x, y, w, h);
  245. //
  246. //
  247. // w = 100;
  248. // h = 30;
  249. // x = (CGRectGetWidth(self.view.frame)-w)/2;
  250. // y = CGRectGetMaxY(self.nextBtn.frame)+50;
  251. // self.pipBtn.frame = CGRectMake(x, y, w, h);
  252. }
  253. - (void)setupPlayer {
  254. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  255. // ZFIJKPlayerManager *playerManager = [[ZFIJKPlayerManager alloc] init];
  256. playerManager.shouldAutoPlay = YES;
  257. /// 播放器相关
  258. self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
  259. self.player.controlView = self.controlView;
  260. /// 设置退到后台继续播放
  261. self.player.pauseWhenAppResignActive = YES;
  262. // self.player.resumePlayRecord = YES;
  263. @zf_weakify(self)
  264. self.player.orientationDidChanged = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
  265. /* // 使用YYTextView转屏失败
  266. for (UIWindow *window in [UIApplication sharedApplication].windows) {
  267. if ([window isKindOfClass:NSClassFromString(@"YYTextEffectWindow")]) {
  268. window.hidden = isFullScreen;
  269. }
  270. }
  271. */
  272. };
  273. /// 播放完成
  274. self.player.playerDidToEnd = ^(id _Nonnull asset) {
  275. @zf_strongify(self)
  276. if (!self.player.isLastAssetURL) {
  277. [self.player playTheNext];
  278. NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
  279. [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape];
  280. } else {
  281. [self.player stop];
  282. }
  283. };
  284. //修改播放速度
  285. self.player.playerPlayStateChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, ZFPlayerPlaybackState playState) {
  286. @zf_strongify(self)
  287. if(playState == ZFPlayerPlayStatePlaying){
  288. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  289. ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager;
  290. manager.rate = self.sp;
  291. });
  292. }
  293. };
  294. }
  295. - (void)picBtnClick {
  296. /// 配置画中画
  297. ZFAVPlayerManager *manager = (ZFAVPlayerManager *)self.player.currentPlayerManager;
  298. AVPictureInPictureController *vc = [[AVPictureInPictureController alloc] initWithPlayerLayer:manager.avPlayerLayer];
  299. self.vc = vc;
  300. ///要有延迟 否则可能开启不成功
  301. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
  302. [self.vc startPictureInPicture];
  303. });
  304. }
  305. - (void)changeVideo:(UIButton *)sender {
  306. 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";
  307. self.player.assetURL = [NSURL URLWithString:URLString];
  308. [self.controlView showTitle:@"AirPods" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
  309. }
  310. - (void)playClick:(UIButton *)sender {
  311. [self.player playTheIndex:0];
  312. [self.controlView showTitle:@"视频标题" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
  313. }
  314. - (void)nextClick:(UIButton *)sender {
  315. if (!self.player.isLastAssetURL) {
  316. [self.player playTheNext];
  317. NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
  318. [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
  319. } else {
  320. NSLog(@"最后一个视频了");
  321. }
  322. }
  323. - (void)pushNewVC {
  324. ZFNotAutoPlayViewController *vc = [[ZFNotAutoPlayViewController alloc] init];
  325. [self.navigationController pushViewController:vc animated:YES];
  326. }
  327. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  328. __weak typeof (self) weakSelf = self;
  329. if(indexPath.row == 0){
  330. playercell1 * cell = [playercell1 cellWithTableView:tableView];
  331. cell.playData = self.playData;
  332. return cell;
  333. }else if(indexPath.row == 1){
  334. playercell2 * cell = [playercell2 cellWithTableView:tableView];
  335. cell.playData =self.playData;
  336. cell.changPlayBlock = ^(int index) {
  337. weakSelf.episodes = index;
  338. [weakSelf requestWatch];
  339. };
  340. return cell;
  341. }else if(indexPath.row == 2){
  342. playercell3 * cell = [playercell3 cellWithTableView:tableView];
  343. return cell;
  344. }else {
  345. playercell4 * cell = [playercell4 cellWithTableView:tableView];
  346. if((indexPath.row-3)*3 + 3>self.reCommondMovies.count){
  347. cell.reCommondMovies = [self.reCommondMovies subarrayWithRange:NSMakeRange((indexPath.row-3)*3, self.reCommondMovies.count-(indexPath.row-3)*3)];
  348. }else{
  349. cell.reCommondMovies = [self.reCommondMovies subarrayWithRange:NSMakeRange((indexPath.row-3)*3, 3)];
  350. }
  351. cell.tapBlock = ^(int index) {
  352. weakSelf.episodes = 1;
  353. weakSelf.vid = index;
  354. [weakSelf requestWatch];
  355. };
  356. return cell;
  357. }
  358. }
  359. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  360. if(self.reCommondMovies.count%3==0){
  361. return 3+self.reCommondMovies.count/3;
  362. }else{
  363. return 3+self.reCommondMovies.count/3+1;
  364. }
  365. }
  366. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
  367. if(indexPath.row == 0){
  368. return 80;
  369. }else if(indexPath.row == 1){
  370. return 122;
  371. }else if(indexPath.row == 2){
  372. return 46;
  373. }else {
  374. return 198;
  375. }
  376. }
  377. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  378. }
  379. -(UIScrollView *)scrollView{
  380. if(!_scrollView){
  381. _scrollView =[UIScrollView new];
  382. _scrollView.showsVerticalScrollIndicator = false;
  383. _scrollView.showsHorizontalScrollIndicator = false;
  384. _scrollView.pagingEnabled = true;
  385. }
  386. return _scrollView;
  387. }
  388. -(UITableView *)tableView{
  389. if(!_tableView){
  390. _tableView =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  391. _tableView.delegate = self;
  392. _tableView.dataSource = self;
  393. _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  394. _tableView.showsVerticalScrollIndicator = false;
  395. _tableView.showsHorizontalScrollIndicator = false;
  396. _tableView.backgroundColor = rgba(18, 23, 41, 1);
  397. // _tableView.backgroundColor = [UIColor redColor];
  398. if (@available(iOS 11, *)) {
  399. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  400. _tableView.estimatedRowHeight = 0;
  401. _tableView.estimatedSectionFooterHeight = 0;
  402. _tableView.estimatedSectionHeaderHeight = 0;
  403. UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  404. UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  405. CGFloat topSafeArea = safeAreaInsets.top;
  406. _tableView.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, 0, 0);
  407. // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
  408. }
  409. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
  410. if (@available(iOS 15.0, *)) {
  411. _tableView.sectionHeaderTopPadding = 0;
  412. }
  413. #endif
  414. }
  415. return _tableView;
  416. }
  417. -(UITableView *)tableView2{
  418. if(!_tableView2){
  419. _tableView2 =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  420. _tableView2.delegate = self;
  421. _tableView2.dataSource = self;
  422. _tableView2.separatorStyle = UITableViewCellSeparatorStyleNone;
  423. _tableView2.showsVerticalScrollIndicator = false;
  424. _tableView2.showsHorizontalScrollIndicator = false;
  425. _tableView2.backgroundColor = rgba(18, 23, 41, 1);
  426. // _tableView.backgroundColor = [UIColor redColor];
  427. if (@available(iOS 11, *)) {
  428. _tableView2.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  429. _tableView2.estimatedRowHeight = 0;
  430. _tableView2.estimatedSectionFooterHeight = 0;
  431. _tableView2.estimatedSectionHeaderHeight = 0;
  432. UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  433. UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  434. CGFloat topSafeArea = safeAreaInsets.top;
  435. _tableView2.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0);
  436. // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
  437. }
  438. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
  439. if (@available(iOS 15.0, *)) {
  440. _tableView2.sectionHeaderTopPadding = 0;
  441. }
  442. #endif
  443. }
  444. return _tableView2;
  445. }
  446. -(UITableView *)tableView3{
  447. if(!_tableView3){
  448. _tableView3 =[[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
  449. _tableView3.delegate = self;
  450. _tableView3.dataSource = self;
  451. _tableView3.separatorStyle = UITableViewCellSeparatorStyleNone;
  452. _tableView3.showsVerticalScrollIndicator = false;
  453. _tableView3.showsHorizontalScrollIndicator = false;
  454. _tableView3.backgroundColor = rgba(18, 23, 41, 1);
  455. // _tableView.backgroundColor = [UIColor redColor];
  456. if (@available(iOS 11, *)) {
  457. _tableView3.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  458. _tableView3.estimatedRowHeight = 0;
  459. _tableView3.estimatedSectionFooterHeight = 0;
  460. _tableView3.estimatedSectionHeaderHeight = 0;
  461. UIWindow *keyWindow = UIApplication.sharedApplication.keyWindow;
  462. UIEdgeInsets safeAreaInsets = keyWindow.safeAreaInsets;
  463. CGFloat topSafeArea = safeAreaInsets.top;
  464. _tableView3.contentInset = UIEdgeInsetsMake(-topSafeArea, 0, BAR_HEIGHT, 0);
  465. // _tableView2.contentInset = UIEdgeInsetsMake(-35, 0, 0, 0);
  466. }
  467. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 150000 // only Xcode 13+ needs and can compile this
  468. if (@available(iOS 15.0, *)) {
  469. _tableView3.sectionHeaderTopPadding = 0;
  470. }
  471. #endif
  472. }
  473. return _tableView3;
  474. }
  475. //- (UIStatusBarStyle)preferredStatusBarStyle {
  476. // return UIStatusBarStyleDefault;
  477. //}
  478. - (BOOL)prefersStatusBarHidden {
  479. return NO;
  480. }
  481. - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
  482. return UIStatusBarAnimationNone;
  483. }
  484. - (BOOL)shouldAutorotate {
  485. return NO;
  486. }
  487. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  488. return UIInterfaceOrientationMaskPortrait;
  489. }
  490. - (ZFPlayerControlView2 *)controlView {
  491. if (!_controlView) {
  492. _controlView = [ZFPlayerControlView2 new];
  493. _controlView.fastViewAnimated = YES;
  494. _controlView.effectViewShow = NO;
  495. _controlView.autoHiddenTimeInterval = 5;
  496. _controlView.autoFadeTimeInterval = 0.5;
  497. _controlView.prepareShowLoading = YES;
  498. _controlView.prepareShowControlView = NO;
  499. _controlView.showCustomStatusBar = YES;
  500. __weak typeof (self) weakSelf = self;
  501. _controlView.speedBtnClickCallback = ^(CGFloat sp){
  502. weakSelf.sp = sp;
  503. ZFAVPlayerManager *manager = (ZFAVPlayerManager *)weakSelf.player.currentPlayerManager;
  504. manager.rate = sp;
  505. };
  506. _controlView.clickBackBlock = ^{
  507. [weakSelf.navigationController popViewControllerAnimated:true];
  508. };
  509. _controlView.nextBtnClickCallback = ^{
  510. int total = [weakSelf.playData[@"simple_info"][@"total_episodes"] intValue];
  511. int current = weakSelf.episodes;
  512. if(current<total){
  513. weakSelf.episodes = current+1;
  514. [weakSelf requestWatch];
  515. }else{
  516. [MBProgressHUD showMessage:@"已是最后一集"];
  517. }
  518. };
  519. _controlView.pBtnClickCallback = ^(NSInteger index,int second) {
  520. NSString *URLString;
  521. NSArray *urls = weakSelf.playData[@"video_urls"];
  522. //1080p
  523. if(index == 0){
  524. //2
  525. URLString = weakSelf.playData[@"video_urls"][urls.count-1];
  526. weakSelf.playQXDIndex = (int)urls.count-1;
  527. //720p
  528. }else if(index == 1){
  529. //1
  530. URLString = weakSelf.playData[@"video_urls"][urls.count-2];
  531. weakSelf.playQXDIndex = (int)urls.count-2;
  532. //480p
  533. }else if(index == 2){
  534. //0
  535. URLString = weakSelf.playData[@"video_urls"][0];
  536. weakSelf.playQXDIndex = 0;
  537. }
  538. if(URLString.length > 0){
  539. weakSelf.player.assetURL = [NSURL URLWithString:URLString];
  540. //weakSelf.playData[@"simple_info"][@"horizontal_cover_url"]
  541. [weakSelf.controlView showTitle:weakSelf.playData[@"simple_info"][@"ch_name"] coverURLString:@"" fullScreenMode:ZFFullScreenModeAutomatic];
  542. [weakSelf.player seekToTime:second completionHandler:^(BOOL finished) {
  543. }];
  544. }
  545. };
  546. }
  547. return _controlView;
  548. }
  549. - (UIImageView *)containerView {
  550. if (!_containerView) {
  551. _containerView = [UIImageView new];
  552. [_containerView setImageWithURLString:kVideoCover placeholder:[ZFUtilities imageWithColor:[UIColor blackColor] size:CGSizeMake(1, 1)]];
  553. }
  554. return _containerView;
  555. }
  556. - (UIButton *)playBtn {
  557. if (!_playBtn) {
  558. _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  559. [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
  560. [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside];
  561. }
  562. return _playBtn;
  563. }
  564. - (UIButton *)changeBtn {
  565. if (!_changeBtn) {
  566. _changeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  567. [_changeBtn setTitle:@"Change video" forState:UIControlStateNormal];
  568. [_changeBtn addTarget:self action:@selector(changeVideo:) forControlEvents:UIControlEventTouchUpInside];
  569. }
  570. return _changeBtn;
  571. }
  572. - (UIButton *)nextBtn {
  573. if (!_nextBtn) {
  574. _nextBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  575. [_nextBtn setTitle:@"Next" forState:UIControlStateNormal];
  576. [_nextBtn addTarget:self action:@selector(nextClick:) forControlEvents:UIControlEventTouchUpInside];
  577. }
  578. return _nextBtn;
  579. }
  580. - (UIButton *)pipBtn {
  581. if (!_pipBtn) {
  582. _pipBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  583. [_pipBtn setTitle:@"开启画中画" forState:UIControlStateNormal];
  584. [_pipBtn addTarget:self action:@selector(picBtnClick) forControlEvents:UIControlEventTouchUpInside];
  585. }
  586. return _pipBtn;
  587. }
  588. - (NSArray<NSURL *> *)assetURLs {
  589. if (!_assetURLs) {
  590. _assetURLs = @[[NSURL URLWithString:self.playData[@"video_urls"][self.playQXDIndex]]];
  591. }
  592. return _assetURLs;
  593. }
  594. //[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"],
  595. // [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"],
  596. // [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"],
  597. // [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"],
  598. // [NSURL URLWithString:@"https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7194236f31b2e1e3da0fe06cfed4ba2b.mp4"],
  599. // [NSURL URLWithString:@"http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"],
  600. // [NSURL URLWithString:@"http://vjs.zencdn.net/v/oceans.mp4"],
  601. // [NSURL URLWithString:@"https://media.w3.org/2010/05/sintel/trailer.mp4"],
  602. // [NSURL URLWithString:@"http://mirror.aarnet.edu.au/pub/TED-talks/911Mothers_2010W-480p.mp4"],
  603. // [NSURL URLWithString:@"https://sample-videos.com/video123/mp4/480/big_buck_bunny_480p_2mb.mp4"]
  604. @end
  605. @interface playercell1()
  606. @end
  607. @implementation playercell1
  608. + (instancetype)cellWithTableView:(UITableView *)tableView{
  609. static NSString *identifier = @"playercell1";
  610. playercell1 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  611. if (cell == nil) {
  612. cell = [[playercell1 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  613. }
  614. return cell;
  615. }
  616. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  617. {
  618. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  619. if (self) {
  620. [self creatView];
  621. }
  622. return self;
  623. }
  624. -(void)addCollectAct{
  625. int vid = [self.playData[@"simple_info"][@"vid"] intValue];
  626. UIButton *btn = [self.contentView viewWithTag:150];
  627. if([UserModel collectContainVid:vid]){
  628. [UserModel delCollect:self.playData[@"simple_info"]];
  629. [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal];
  630. [btn setTitle:@" 收藏" forState:UIControlStateNormal];
  631. }else{
  632. [UserModel addCollect:self.playData[@"simple_info"]];
  633. [btn setTitle:@"已收藏" forState:UIControlStateNormal];
  634. [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
  635. }
  636. }
  637. -(void)setPlayData:(NSDictionary *)playData {
  638. _playData = playData;
  639. UILabel *lab = [self.contentView viewWithTag:100];
  640. lab.text = playData[@"simple_info"][@"ch_name"];
  641. UILabel *lab2 = [self.contentView viewWithTag:101];
  642. lab2.text = [NSString stringWithFormat:@"%.1f分",[playData[@"simple_info"][@"score"] floatValue]];
  643. UILabel *lab3 = [self.contentView viewWithTag:102];
  644. NSArray *arr = playData[@"simple_info"][@"class_list"];
  645. NSString *t3=@"";
  646. for(int i=0;i<arr.count;i++){
  647. t3 = [NSString stringWithFormat:@"%@%@/",t3,arr[i][@"classname"]];
  648. }
  649. if(t3.length>0){
  650. lab3.text = [t3 substringToIndex:t3.length-1];
  651. }
  652. int vid = [playData[@"simple_info"][@"vid"] intValue];
  653. UIButton *btn = [self.contentView viewWithTag:150];
  654. if([UserModel collectContainVid:vid]){
  655. [btn setTitle:@"已收藏" forState:UIControlStateNormal];
  656. [btn setImage:[UserModel imageWithColor:[UIColor clearColor]] forState:UIControlStateNormal];
  657. }else{
  658. [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal];
  659. [btn setTitle:@" 收藏" forState:UIControlStateNormal];
  660. }
  661. }
  662. -(void)creatView{
  663. self.selectionStyle = UITableViewCellSelectionStyleNone;
  664. self.backgroundColor = [UIColor clearColor];
  665. UILabel *lab = [UILabel new];
  666. lab.text = @"勇敢者的游戏";
  667. lab.tag = 100;
  668. lab.textColor = rgba(255, 255, 255, 1);
  669. lab.font = [UIFont boldSystemFontOfSize:20];
  670. [self.contentView addSubview:lab];
  671. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  672. make.top.equalTo(self.contentView).offset(16);
  673. make.left.equalTo(self.contentView).offset(12);
  674. }];
  675. UILabel *lab2 = [UILabel new];
  676. lab2.text = @"9.6分";
  677. lab2.tag = 101;
  678. lab2.textColor = rgba(255, 212, 0, 1);
  679. lab2.font = [UIFont systemFontOfSize:12];
  680. lab2.backgroundColor = rgba(247, 187, 1, 0.2);
  681. lab2.textAlignment = NSTextAlignmentCenter;
  682. [self.contentView addSubview:lab2];
  683. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  684. make.top.equalTo(lab.mas_bottom).offset(14);
  685. make.left.equalTo(self.contentView).offset(12);
  686. make.size.mas_equalTo(CGSizeMake(50, 24));
  687. }];
  688. UILabel *lab3 = [UILabel new];
  689. lab3.tag = 102;
  690. lab3.text = @"悬疑/罪案/动作";
  691. lab3.textColor = rgba(255, 255, 255, 0.4);
  692. lab3.font = [UIFont systemFontOfSize:12];
  693. [self.contentView addSubview:lab3];
  694. [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
  695. make.centerY.equalTo(lab2);
  696. make.left.equalTo(lab2.mas_right).offset(6);
  697. }];
  698. UIButton *btn = [UIButton new];
  699. btn.tag = 150;
  700. [btn setImage:[UIImage imageNamed:@"Frame14"] forState:UIControlStateNormal];
  701. [btn setTitle:@" 收藏" forState:UIControlStateNormal];
  702. btn.titleLabel.font = [UIFont systemFontOfSize:12];
  703. [btn setTitleColor:rgba(255, 255, 255, 0.4) forState:UIControlStateNormal];
  704. [btn setBackgroundColor:rgba(255, 255, 255, 0.03)];
  705. [btn addTarget:self action:@selector(addCollectAct) forControlEvents:UIControlEventTouchUpInside];
  706. [self.contentView addSubview:btn];
  707. [btn mas_makeConstraints:^(MASConstraintMaker *make) {
  708. make.centerY.equalTo(lab2);
  709. make.right.equalTo(self.contentView).offset(-28);
  710. make.size.mas_equalTo(CGSizeMake(74, 30));
  711. }];
  712. lab2.layer.cornerRadius = 8;
  713. lab2.layer.masksToBounds = true;
  714. btn.layer.cornerRadius = 8;
  715. btn.layer.masksToBounds = true;
  716. }
  717. @end
  718. @interface playercell2()<UICollectionViewDelegate,UICollectionViewDataSource>
  719. @property(nonatomic,strong)UICollectionView *collect;
  720. @property(nonatomic,assign)int count;
  721. @end
  722. @implementation playercell2
  723. + (instancetype)cellWithTableView:(UITableView *)tableView{
  724. static NSString *identifier = @"playercell2";
  725. playercell2 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  726. if (cell == nil) {
  727. cell = [[playercell2 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  728. }
  729. return cell;
  730. }
  731. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  732. {
  733. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  734. if (self) {
  735. [self creatView];
  736. }
  737. return self;
  738. }
  739. -(void)setPlayData:(NSDictionary *)playData{
  740. _playData = playData;
  741. self.count = [playData[@"simple_info"][@"total_episodes"] intValue];
  742. [self.collect reloadData];
  743. }
  744. -(void)creatView{
  745. self.selectionStyle = UITableViewCellSelectionStyleNone;
  746. self.backgroundColor = [UIColor clearColor];
  747. UILabel *lab = [UILabel new];
  748. lab.text = @"选集";
  749. lab.textColor = rgba(255, 255, 255, 1);
  750. lab.font = [UIFont boldSystemFontOfSize:16];
  751. [self.contentView addSubview:lab];
  752. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  753. make.top.equalTo(self.contentView).offset(24);
  754. make.left.equalTo(self.contentView).offset(12);
  755. }];
  756. UILabel *lab2 = [UILabel new];
  757. // lab2.text = @"每周二、周三凌晨更新";
  758. lab2.textColor = rgba(255, 255, 255, 0.4);
  759. lab2.font = [UIFont systemFontOfSize:12];
  760. lab2.textAlignment = NSTextAlignmentCenter;
  761. [self.contentView addSubview:lab2];
  762. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  763. make.centerY.equalTo(lab);
  764. make.left.equalTo(lab.mas_right).offset(8);
  765. }];
  766. UIView *bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-12, 64)];
  767. bg.backgroundColor = rgba(255, 255, 255, 0.03);
  768. [self.contentView addSubview:bg];
  769. [bg mas_makeConstraints:^(MASConstraintMaker *make) {
  770. make.left.equalTo(self.contentView).offset(12);
  771. make.top.equalTo(lab.mas_bottom).offset(12);
  772. make.right.equalTo(self.contentView);
  773. make.height.mas_equalTo(@64);
  774. // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-12, 64));
  775. }];
  776. [self.contentView addSubview:self.collect];
  777. [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
  778. make.left.equalTo(self.contentView).offset(12);
  779. make.top.equalTo(lab.mas_bottom).offset(12);
  780. make.right.equalTo(self.contentView);
  781. make.height.mas_equalTo(@64);
  782. // make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH-12, 64));
  783. }];
  784. // 创建圆角图层
  785. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:bg.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(8, 8)];
  786. CAShapeLayer *maskLayer = [CAShapeLayer layer];
  787. maskLayer.path = path.CGPath;
  788. bg.layer.mask = maskLayer;
  789. }
  790. -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  791. playItemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([playItemCell class]) forIndexPath:indexPath];
  792. cell.index = indexPath.row+1;
  793. if(indexPath.row == [self.playData[@"episodes"] intValue]-1){
  794. cell.isSel = true;
  795. }else{
  796. cell.isSel = false;
  797. }
  798. return cell;
  799. }
  800. -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
  801. if(self.changPlayBlock){
  802. self.changPlayBlock((int)indexPath.row+1);
  803. }
  804. }
  805. -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
  806. return [self.playData[@"simple_info"][@"total_episodes"] intValue];
  807. }
  808. - (UICollectionView *)collect {
  809. if (!_collect) {
  810. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  811. layout.itemSize = CGSizeMake(48, 48);
  812. layout.minimumLineSpacing = 8; //跟滚动方向相同的间距
  813. // layout.minimumInteritemSpacing = 8; //跟滚动方向垂直的间距
  814. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  815. _collect = [[UICollectionView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH-12, 64) collectionViewLayout:layout];
  816. _collect.contentInset = UIEdgeInsetsMake(8, 12, 8, 12);
  817. //注册cell
  818. [_collect registerClass:[playItemCell class] forCellWithReuseIdentifier:@"playItemCell"];
  819. // [_collect registerClass:[SearchItemCell class] forCellWithReuseIdentifier:@"SearchItemCell"];
  820. // [_collect registerClass:[FoundCell class] forCellWithReuseIdentifier:@"FoundCell"];
  821. // [_collect registerClass:[HotSearchCell class] forCellWithReuseIdentifier:@"HotSearchCell"];
  822. _collect.dataSource = self;
  823. _collect.delegate = self;
  824. _collect.backgroundColor = [UIColor clearColor];
  825. _collect.showsVerticalScrollIndicator = false;
  826. _collect.showsHorizontalScrollIndicator = false;
  827. }
  828. return _collect;
  829. }
  830. @end
  831. @interface playItemCell()
  832. @property(nonatomic,strong)UILabel *lab;
  833. @property(nonatomic,strong)UIImageView *iv;
  834. @end
  835. @implementation playItemCell
  836. - (instancetype)initWithFrame:(CGRect)frame
  837. {
  838. self = [super initWithFrame:frame];
  839. if (self) {
  840. [self setUp];
  841. }
  842. return self;
  843. }
  844. -(void)setIndex:(NSInteger)index{
  845. _index = index;
  846. self.lab.text = [NSString stringWithFormat:@"%ld",(long)index];
  847. }
  848. - (void)setIsSel:(BOOL)isSel{
  849. _isSel = isSel;
  850. if(isSel){
  851. self.lab.backgroundColor = rgba(247, 187, 1, 0.2);
  852. self.lab.textColor = rgba(255, 212, 0, 1);
  853. self.iv.hidden = false;
  854. }else{
  855. self.lab.backgroundColor = rgba(18, 23, 41, 1);
  856. self.lab.textColor = rgba(255, 255, 255, 0.4);
  857. self.iv.hidden = true;
  858. }
  859. }
  860. - (void)setUp {
  861. self.backgroundColor = [UIColor clearColor];
  862. //选中背景 rgba(247, 187, 1, 0.2)
  863. UILabel *lab = [UILabel new];
  864. self.lab= lab;
  865. // lab.text = @"选集";
  866. lab.textColor = rgba(255, 255, 255, 0.4);
  867. lab.font = [UIFont boldSystemFontOfSize:16];
  868. lab.textAlignment = NSTextAlignmentCenter;
  869. [self.contentView addSubview:lab];
  870. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  871. make.edges.equalTo(self.contentView);
  872. }];
  873. UIImageView *iv = [UIImageView new];
  874. iv.image = [UIImage imageNamed:@"Group 427319579"];
  875. self.iv = iv;
  876. [self.contentView addSubview:iv];
  877. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  878. make.left.equalTo(self.contentView).offset(6);
  879. make.bottom.equalTo(self.contentView).offset(-5);
  880. make.size.mas_equalTo(CGSizeMake(10, 10));
  881. }];
  882. self.lab.layer.cornerRadius = 8;
  883. self.lab.layer.masksToBounds = true;
  884. }
  885. @end
  886. @interface playercell3 ()
  887. @end
  888. @implementation playercell3
  889. + (instancetype)cellWithTableView:(UITableView *)tableView{
  890. static NSString *identifier = @"playercell3";
  891. playercell3 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  892. if (cell == nil) {
  893. cell = [[playercell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  894. }
  895. return cell;
  896. }
  897. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  898. {
  899. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  900. if (self) {
  901. [self creatView];
  902. }
  903. return self;
  904. }
  905. -(void)creatView{
  906. self.selectionStyle = UITableViewCellSelectionStyleNone;
  907. self.backgroundColor = [UIColor clearColor];
  908. UILabel *lab = [UILabel new];
  909. lab.text = @"猜你喜欢";
  910. lab.textColor = rgba(255, 255, 255, 1);
  911. lab.font = [UIFont boldSystemFontOfSize:16];
  912. [self.contentView addSubview:lab];
  913. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  914. make.top.equalTo(self.contentView).offset(24);
  915. make.left.equalTo(self.contentView).offset(12);
  916. }];
  917. UIImageView *iv = [UIImageView new];
  918. // iv.image = [UIImage imageNamed:@"Frame 9391"];
  919. [self.contentView addSubview:iv];
  920. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  921. make.centerY.equalTo(lab);
  922. make.right.equalTo(self.contentView).offset(-12);
  923. make.size.mas_equalTo(CGSizeMake(12, 12));
  924. }];
  925. UILabel *lab2 = [UILabel new];
  926. // lab2.text = @"查看更多";
  927. lab2.textColor = rgba(255, 255, 255, 0.4);
  928. lab2.font = [UIFont systemFontOfSize:12];
  929. [self.contentView addSubview:lab2];
  930. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  931. make.centerY.equalTo(lab);
  932. make.right.equalTo(iv.mas_left);
  933. }];
  934. }
  935. @end
  936. @interface playercell4 ()
  937. @end
  938. @implementation playercell4
  939. + (instancetype)cellWithTableView:(UITableView *)tableView{
  940. static NSString *identifier = @"playercell4";
  941. playercell4 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  942. if (cell == nil) {
  943. cell = [[playercell4 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  944. }
  945. return cell;
  946. }
  947. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  948. {
  949. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  950. if (self) {
  951. [self creatView];
  952. }
  953. return self;
  954. }
  955. -(void)setReCommondMovies:(NSArray *)reCommondMovies{
  956. _reCommondMovies = reCommondMovies;
  957. for(int i=0;i<3;i++){
  958. if(i<reCommondMovies.count){
  959. UIImageView *iv = [self.contentView viewWithTag:100+i];
  960. iv.hidden = false;
  961. [iv sd_setImageWithURL:[NSURL URLWithString:reCommondMovies[i][@"vertical_cover_url"]]];
  962. UILabel *lab = [self.contentView viewWithTag:200+i];
  963. lab.text = [NSString stringWithFormat:@"%.1f",[reCommondMovies[i][@"score"] floatValue]];
  964. UILabel *lab2 = [self.contentView viewWithTag:300+i];
  965. lab2.text = reCommondMovies[i][@"ch_name"];
  966. }else{
  967. UIImageView *iv = [self.contentView viewWithTag:100+i];
  968. iv.hidden = true;
  969. // [iv sd_setImageWithURL:[NSURL URLWithString:reCommondMovies[i][@"vertical_cover_url"]]];
  970. UILabel *lab = [self.contentView viewWithTag:200+i];
  971. lab.text = @"";
  972. UILabel *lab2 = [self.contentView viewWithTag:300+i];
  973. lab2.text = @"";
  974. }
  975. }
  976. }
  977. -(void)clickAct:(UITapGestureRecognizer *)g{
  978. NSInteger x = g.view.tag - 100;
  979. int vid = [self.reCommondMovies[x][@"vid"] intValue];
  980. if(self.tapBlock){
  981. self.tapBlock(vid);
  982. }
  983. }
  984. -(void)creatView{
  985. self.selectionStyle = UITableViewCellSelectionStyleNone;
  986. self.backgroundColor = [UIColor clearColor];
  987. CGFloat m = (kScreenWidth - 3*112 - 24)/2;
  988. for(int i=0;i<3;i++){
  989. UIImageView *iv = [UIImageView new];
  990. iv.userInteractionEnabled = true;
  991. // iv.backgroundColor = [UIColor redColor];
  992. iv.tag = 100+i;
  993. iv.image = [UIImage imageNamed:@""];
  994. [self.contentView addSubview:iv];
  995. UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickAct:)];
  996. [iv addGestureRecognizer:g];
  997. [iv mas_makeConstraints:^(MASConstraintMaker *make) {
  998. make.size.mas_equalTo(CGSizeMake(112, 146));
  999. make.left.equalTo(self.contentView).offset(12+(112+m)*i);
  1000. make.top.equalTo(self.contentView).offset(12);
  1001. }];
  1002. UILabel *lab = [UILabel new];
  1003. lab.text = @"9.7";
  1004. lab.tag =200+i;
  1005. lab.textColor = rgba(255, 212, 0, 1);
  1006. lab.font = [UIFont boldSystemFontOfSize:16];
  1007. [iv addSubview:lab];
  1008. [lab mas_makeConstraints:^(MASConstraintMaker *make) {
  1009. make.bottom.equalTo(iv).offset(-6);
  1010. make.right.equalTo(iv).offset(-8);
  1011. }];
  1012. UILabel *lab2 = [UILabel new];
  1013. lab2.text = @"摩天大楼";
  1014. lab2.tag = 300+i;
  1015. lab2.textColor = rgba(255, 255, 255, 1);
  1016. lab2.font = [UIFont systemFontOfSize:14];
  1017. [self.contentView addSubview:lab2];
  1018. [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
  1019. make.top.equalTo(iv.mas_bottom).offset(8);
  1020. make.left.equalTo(iv);
  1021. }];
  1022. iv.layer.cornerRadius = 8;
  1023. iv.layer.masksToBounds = true;
  1024. }
  1025. }
  1026. @end