YBLookVideoVC.m 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  1. //
  2. // YBLookVideoVC.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/11/6.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBLookVideoVC.h"
  9. #import <ZFPlayer/ZFPlayer.h>
  10. #import <ZFPlayer/ZFPlayerControlView.h>
  11. #import <ZFPlayer/ZFIJKPlayerManager.h>
  12. //#import <ZFPlayer/KSMediaPlayerManager.h>
  13. #import <ZFPlayer/ZFAVPlayerManager.h>
  14. #import "YBVideoControlView.h"
  15. #import "YBLookVideoCell.h"
  16. #import "YBVipVC.h"
  17. #import "YBRechargeVC.h"
  18. #import "YBCommentToolBar.h"
  19. #import "twEmojiView.h"
  20. #import "YBTabBarController.h"
  21. #import "YBUploadProgress.h"
  22. #import "Loginbonus.h" //每天第一次登录
  23. #import "ZZCircleProgress.h"
  24. #import "YBRedProfitVC.h"
  25. #import "ZFCustomControlView.h"
  26. #import "YBHomeRedObj.h"
  27. #import "RegAlertView.h"
  28. static NSString * const reuseIdentifier = @"collectionViewCell";
  29. @interface YBLookVideoVC ()<UICollectionViewDelegate,UICollectionViewDataSource,FirstLogDelegate>//homeRedDelegate
  30. {
  31. int _lastPlayCellIndex;
  32. //rk_1-30
  33. BOOL _isDoubleClickRefresh; //是否是双击刷新
  34. BOOL _isHome;
  35. BOOL _needCheckLimit; //是否需要检查播放权限
  36. BOOL _isLoadingMore; //列表是否正在加载总
  37. CGFloat lastContenOffset;
  38. BOOL _isFirstPlay;
  39. NSDictionary *_currentVideoDic;
  40. RKPlayerLeaveState _playerLeaveState;
  41. Loginbonus *firstLV;
  42. NSString *bonus_switch;
  43. NSString *bonus_day;
  44. NSArray *bonus_list;
  45. NSString *dayCount;
  46. NSString *is_bonus;//是否签到
  47. ZZCircleProgress *progressView;
  48. UIButton *_normalBtn;
  49. NSDictionary *rulesDic;
  50. }
  51. @property(nonatomic,strong)NSString *hostID; //视频主人ID
  52. @property(nonatomic,copy)NSString *videoID; //视频id
  53. @property (nonatomic, strong) NSMutableArray *videoUrls;
  54. @property (nonatomic, strong) UICollectionView *collectionView;
  55. @property (nonatomic, strong) ZFPlayerController *player;
  56. @property (nonatomic, strong) YBVideoControlView *controlView;
  57. @property (nonatomic, strong) ZFCustomControlView *fullControlView;
  58. @property (nonatomic, strong) UIButton *backBtn;
  59. @property(nonatomic,strong)YBLookVideoCell *playingCell;
  60. @property(nonatomic,strong)YBCommentToolBar *commentTool;
  61. @property(nonatomic,strong)YBUploadProgress *uploadView;
  62. @end
  63. @implementation YBLookVideoVC
  64. /// 青少年模式切换,刷新首页
  65. -(void)youngModeRefresh;{
  66. [self doubleClickRefreshForYou];
  67. _isDoubleClickRefresh = NO;
  68. }
  69. //rk_1-30
  70. -(void)doubleClickRefreshForYou {
  71. if([_fromWhere isEqual:@"MsgTopPubVC"] ||[_fromWhere isEqual:@"NearbyVC"]){
  72. return;
  73. }
  74. //双击首页刷新推荐
  75. _isDoubleClickRefresh = YES;
  76. _needCheckLimit = YES;
  77. _pages = 1;
  78. [self.player stopCurrentPlayingCell];
  79. if (_videoList.count>0) {
  80. [_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
  81. }
  82. [_videoList removeAllObjects];
  83. [MBProgressHUD showMessage:@""];
  84. [self pullData];
  85. }
  86. - (void)viewDidLoad {
  87. [super viewDidLoad];
  88. self.naviView.hidden = YES;
  89. _lastPlayCellIndex = -1;
  90. _isDoubleClickRefresh = NO;
  91. _isLoadingMore = NO;
  92. lastContenOffset = 0;
  93. _isFirstPlay = NO;
  94. _currentVideoDic = @{};
  95. [self addNotifications];
  96. [self.view addSubview:self.collectionView];
  97. if (![PublicObj checkNull:minstr(_fromWhere)]) {
  98. [self.view addSubview:self.backBtn];
  99. [self.view addSubview:self.commentTool];
  100. }else{
  101. [self.view addSubview:self.uploadView];
  102. }
  103. self.videoUrls = [NSMutableArray array];
  104. if (!_videoList || _videoList.count <= 0) {
  105. //首页
  106. _isHome = YES;
  107. _needCheckLimit = YES;
  108. _pages = 1;
  109. self.videoList = [NSMutableArray array];
  110. [self pullData];
  111. }else {
  112. //其他页面push
  113. _isHome = NO;
  114. _needCheckLimit = NO;
  115. for (NSDictionary *subDic in _videoList) {
  116. NSString *videoUrl = minstr([subDic valueForKey:@"href"]);
  117. [_videoUrls addObject:[NSURL URLWithString:[PublicObj decrypt:videoUrl]]];
  118. }
  119. [self.player stopCurrentPlayingCell];
  120. [_collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:_pushPlayIndex inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
  121. }
  122. /// playerManager
  123. ZFIJKPlayerManager *playerManager = [[ZFIJKPlayerManager alloc] init];
  124. NSString *ijkRef = [NSString stringWithFormat:@"Referer:%@\r\n",h5url];
  125. [playerManager.options setFormatOptionValue:ijkRef forKey:@"headers"];
  126. //KSMediaPlayer 设置referer需要在 KSMediaPlayerManager 的初始化里边
  127. // KSMediaPlayerManager *playerManager = [[KSMediaPlayerManager alloc]init];
  128. // [playerManager setRequestHeader:@{@"Referer":h5url}];
  129. // ZFAVPlayerManager*playerManager = [[ZFAVPlayerManager alloc] init];
  130. // NSDictionary *header = @{@"Referer":h5url};
  131. // NSDictionary *optiosDic = @{@"AVURLAssetHTTPHeaderFieldsKey" : header};
  132. // [playerManager setRequestHeader:optiosDic];
  133. /// player的tag值必须在cell里设置
  134. self.player = [ZFPlayerController playerWithScrollView:self.collectionView playerManager:playerManager containerViewTag:191107];
  135. self.player.controlView = self.controlView;
  136. self.player.assetURLs = self.videoUrls;
  137. self.player.shouldAutoPlay = YES;
  138. self.player.allowOrentitaionRotation = NO;
  139. self.player.WWANAutoPlay = YES;
  140. //不支持的方向
  141. self.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionVertical;
  142. //不支持的手势类型
  143. self.player.disableGestureTypes = ZFPlayerDisableGestureTypesPinch;
  144. /// 1.0是消失100%时候
  145. self.player.playerDisapperaPercent = 1.0;
  146. @weakify(self)
  147. self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
  148. // @strongify(self)
  149. // AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
  150. // app.allowOrentitaionRotation = isFullScreen;
  151. @zf_strongify(self)
  152. if (isFullScreen) {
  153. self.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionNone;
  154. } else {
  155. self.player.disablePanMovingDirection = ZFPlayerDisablePanMovingDirectionAll;
  156. }
  157. self.player.controlView.hidden = YES;
  158. };
  159. self.player.orientationDidChanged = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
  160. @strongify(self)
  161. self.player.controlView.hidden = NO;
  162. if (isFullScreen) {
  163. self.player.controlView = self.fullControlView;
  164. } else {
  165. self.player.controlView = self.controlView;
  166. }
  167. [self orientationDidChangedResetTool];
  168. };
  169. self.player.presentationSizeChanged = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, CGSize size) {
  170. @strongify(self)
  171. if (size.width >= size.height) {
  172. self.player.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFit;
  173. } else {
  174. self.player.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFill;
  175. }
  176. };
  177. //功能
  178. self.player.playerPrepareToPlay = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSURL * _Nonnull assetURL) {
  179. NSLog(@"准备");
  180. @strongify(self)
  181. _isFirstPlay = YES;
  182. [self videoStart];
  183. };
  184. self.player.playerDidToEnd = ^(id _Nonnull asset) {
  185. NSLog(@"结束");
  186. @strongify(self)
  187. [self.player.currentPlayerManager replay];
  188. if (_isFirstPlay == YES) {
  189. _isFirstPlay = NO;
  190. [self videoEnd];
  191. [self addLookTimeForToday:[NSString stringWithFormat:@"%.0f",self.player.totalTime]];
  192. }
  193. };
  194. self.player.zf_playerDisappearingInScrollView = ^(NSIndexPath * _Nonnull indexPath, CGFloat playerDisapperaPercent) {
  195. @strongify(self);
  196. //这里代表将要切换视频
  197. if (playerDisapperaPercent == 1) {
  198. NSLog(@"100%%消失:%f",self.player.currentTime);
  199. _needCheckLimit = YES;
  200. if (_isFirstPlay == YES) {
  201. [self addLookTimeForToday:[NSString stringWithFormat:@"%.0f",self.player.currentTime]];
  202. }
  203. YBLookVideoCell *disCell = (YBLookVideoCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
  204. [disCell releaseObj:self.videoList[indexPath.row] isBackGround:NO];
  205. //上一个结束动画
  206. [disCell stopMusicAnimation:self.videoList[indexPath.row]];
  207. }
  208. };
  209. //停止的时候找出最合适的播放
  210. self.player.zf_scrollViewDidEndScrollingCallback = ^(NSIndexPath * _Nonnull indexPath) {
  211. @strongify(self)
  212. if (self.player.playingIndexPath) return;
  213. if (indexPath.row + 1 >= _videoList.count) {
  214. //加载下一页数据
  215. _pages += 1;
  216. [MBProgressHUD showMessage:@""];
  217. [self pullData];
  218. }else {
  219. [self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
  220. }
  221. };
  222. [self showHomeVideoRed];
  223. }
  224. -(void)orientationDidChangedResetTool {
  225. // NSLog(@"rk===>[tool]:%d",_commentTool.isPrepareEditing);
  226. // NSLog(@"rk===>[tool]:%@",_commentTool);
  227. _commentTool.frame = CGRectMake(0,_window_height - 50-ShowDiff, _window_width, 50+ShowDiff);
  228. _commentTool.emojiV.frame = CGRectMake(0, _window_height, _window_width, EmojiHeight+ShowDiff);
  229. }
  230. -(void)showHomeVideoRed{
  231. if ([[Config getOwnID] intValue] <= 0) {
  232. }else{
  233. if([[common getVideoAwardSwitch] isEqual:@"1"]){
  234. [self requestWatchAward];
  235. }
  236. }
  237. // _isDoubleClickRefresh = NO;
  238. // [self doubleClickRefreshForYou];
  239. }
  240. -(void)hideHomeVideoRed{
  241. if(progressView){
  242. [progressView removeFromSuperview];
  243. progressView =nil;
  244. }
  245. [YBHomeRedObj redInstance].lookCount = 0;
  246. [YBHomeRedObj redInstance].startFloattime = 0.0f;
  247. [[YBHomeRedObj redInstance]timerEnd];
  248. _isDoubleClickRefresh = NO;
  249. [self doubleClickRefreshForYou];
  250. }
  251. -(void)tapsRedClick{
  252. YBRedProfitVC *vc = [[YBRedProfitVC alloc]init];
  253. vc.hidesBottomBarWhenPushed = YES;
  254. [[YBBaseAppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  255. }
  256. #pragma mark ---红包开始
  257. -(void)requestWatchAward{
  258. if(!progressView){
  259. progressView = [[ZZCircleProgress alloc] initWithFrame:CGRectMake(20,statusbarHeight+24+70, 60, 60) pathBackColor:[UIColor clearColor] pathFillColor:Pink_Cor startAngle:-90 strokeWidth:3];
  260. progressView.increaseFromLast = YES;//进度条动画是否从上次进度开始动画。默认为NO
  261. progressView.showPoint = NO;//是否显示默认小圆点。默认为YES
  262. progressView.showProgressText = NO;
  263. progressView.duration = 0.1;
  264. [self.view addSubview:progressView];
  265. UITapGestureRecognizer *taps = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapsRedClick)];
  266. [progressView addGestureRecognizer:taps];
  267. NSDictionary *dic = @{
  268. @"uid":[Config getOwnID],
  269. @"touid":[Config getOwnID],
  270. };
  271. [YBNetworking postWithUrl:@"Video.getWatchVideoSeconds" Dic:dic Suc:^(int code, id info, NSString *msg) {
  272. if(code == 0){
  273. NSDictionary *infos = [info firstObject];
  274. if ([minstr([infos valueForKey:@"can_receive"]) isEqual:@"1"]) {
  275. [[YBHomeRedObj redInstance]initWithTimer];
  276. [[YBHomeRedObj redInstance]lookTimerStart];
  277. [YBHomeRedObj redInstance].startEvent = ^(CGFloat currentTime) {
  278. dispatch_async(dispatch_get_main_queue(), ^{
  279. progressView.progress =currentTime;
  280. NSLog(@"sdsadsadsd-----:%@",_videoID);
  281. });
  282. };
  283. }else{
  284. [YBHomeRedObj redInstance].lookCount = 60;
  285. progressView.progress = 1;
  286. }
  287. }
  288. } Fail:^(id fail) {
  289. }];
  290. }
  291. else{
  292. [YBHomeRedObj redInstance].startEvent = ^(CGFloat currentTime) {
  293. dispatch_async(dispatch_get_main_queue(), ^{
  294. progressView.progress =currentTime;
  295. NSLog(@"sdsadsadsd--wwewwwww---:%@",_videoID);
  296. });
  297. };
  298. }
  299. }
  300. -(void)homeRedReloadTime:(CGFloat)currentTime{
  301. progressView.progress =currentTime;
  302. }
  303. -(void)timeGo{
  304. [[YBHomeRedObj redInstance]timerBegin];
  305. }
  306. #pragma mark ---红包结束
  307. - (BOOL)shouldAutorotate {
  308. return NO;
  309. }
  310. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  311. return UIInterfaceOrientationMaskPortrait;
  312. }
  313. - (UIStatusBarStyle)preferredStatusBarStyle {
  314. return UIStatusBarStyleDefault;
  315. }
  316. - (BOOL)prefersStatusBarHidden {
  317. // return [self.player isFullScreen];
  318. return NO;
  319. }
  320. //-(void)addAllFunctionBtn{
  321. // if(!_normalBtn){
  322. // _normalBtn = [UIButton buttonWithType:0];
  323. // _normalBtn.frame = CGRectMake(_window_width *0.15, _window_height *0.8, _window_width *0.7, 40);
  324. // _normalBtn.layer.cornerRadius = 20;
  325. // _normalBtn.layer.masksToBounds = YES;
  326. // [_normalBtn setBackgroundColor:Pink_Cor];
  327. // [_normalBtn setTitle:YZMsg(@"进入全功能模式") forState:0];
  328. // [_normalBtn setTitleColor:UIColor.whiteColor forState:0];
  329. // _normalBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  330. // [_normalBtn addTarget:self action:@selector(normalBtnClick) forControlEvents:UIControlEventTouchUpInside];
  331. //// [self.view addSubview:_normalBtn];
  332. //// _normalBtn.hidden = YES;
  333. //
  334. // }
  335. //}
  336. //-(void)normalBtnClick{
  337. // [self showPrivateRule:rulesDic andIsFirst:NO];
  338. //}
  339. - (void)viewWillAppear:(BOOL)animated {
  340. [super viewWillAppear:animated];
  341. [IQKeyboardManager sharedManager].enable = NO;
  342. [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
  343. [self.controlView.zfVolumeView removeSystemVolumeView];
  344. _controlView.isDisappear = NO;
  345. if ([PublicObj checkNull:_fromWhere]) {
  346. [[NSUserDefaults standardUserDefaults]setObject:@"1" forKey:@"show_share_pop"];
  347. }
  348. [[YBDayTaskManager shareInstance]taskOfWatchVideoStart];
  349. [self.playingCell checkLiveOrAdState:_videoList[self.player.playingIndexPath.row]];
  350. [self ctrUpdateVideoInfo];
  351. //每天第一次登录
  352. if ([[Config getOwnID]intValue] > 0) {
  353. [self pullInternet];
  354. }
  355. // else{
  356. // [self getLoginThird];
  357. // }
  358. // [self addAllFunctionBtn];
  359. // if ([[Config getOwnID] intValue]>0 && [Config getTranslate]) {
  360. // _normalBtn.hidden = YES;
  361. // }
  362. }
  363. - (void)viewDidAppear:(BOOL)animated {
  364. [super viewDidAppear:animated];
  365. // [self timerBegin];
  366. if ([[Config getOwnID] intValue] <= 0) {
  367. }else{
  368. if([[common getVideoAwardSwitch] isEqual:@"1"]){
  369. [[YBHomeRedObj redInstance]timerBegin];
  370. [self requestWatchAward];
  371. }
  372. }
  373. // if (_videoList.count<=0) {
  374. // return;
  375. // }
  376. //当前的开始动画
  377. [self.playingCell startMusicAnimation:_videoList[self.player.playingIndexPath.row]];
  378. //当从个人中心删除(或者游客登录)了视频时做个标记当返回推荐时候重新请求数据
  379. NSString *sign_del = [Config getSignOfDelVideo];
  380. if ([sign_del isEqual:@"1"]&&!_fromWhere) {
  381. [Config saveSignOfDelVideo:@"0"];
  382. [_videoList removeAllObjects];
  383. _needCheckLimit = YES;
  384. _pages = 1;
  385. [self pullData];
  386. }else if (!_isHome && !self.player.currentPlayerManager.isPlaying) {
  387. if (_firstPush) {
  388. _firstPush = NO;
  389. if (_pushPlayIndex + 1 >= _videoList.count && ![PublicObj checkNull:minstr(_sourceBaseUrl)]) {
  390. /// 加载下一页数据
  391. _pages += 1;
  392. [MBProgressHUD showMessage:@""];
  393. [self pullData];
  394. }else {
  395. [self startPlayerVideo];
  396. }
  397. return;
  398. }
  399. //NSLog(@"=====home:%lu",(unsigned long)self.player.currentPlayerManager.playState);
  400. ///播放离开回来继续播放,暂停离开回来还是暂停状态-start
  401. if (_playerLeaveState == RKLeaveState_Playing && self.player.currentPlayerManager.playState == 2) {
  402. [_controlView controlSingleTapped];
  403. }else if (_playerLeaveState == RKLeaveState_Pause){
  404. }else{
  405. [self startPlayerVideo];
  406. }
  407. ///播放离开回来继续播放,暂停离开回来还是暂停状态-end
  408. }
  409. }
  410. /**********************每天第一次登录-->>**********************/
  411. -(void)pullInternet {
  412. [YBNetworking postWithUrl:@"User.Bonus" Dic:nil Suc:^(int code, id info, NSString *msg) {
  413. if (code == 0) {
  414. NSArray *infos = info;
  415. bonus_switch = [NSString stringWithFormat:@"%@",[[infos lastObject] valueForKey:@"bonus_switch"]];
  416. bonus_day = [[infos lastObject] valueForKey:@"bonus_day"];
  417. bonus_list = [[infos lastObject] valueForKey:@"bonus_list"];
  418. dayCount = minstr([[infos lastObject] valueForKey:@"count_day"]);
  419. is_bonus = minstr([[infos lastObject] valueForKey:@"is_bonus"]);
  420. if ([bonus_switch isEqual:@"1"] &&
  421. [is_bonus isEqual:@"0"] &&
  422. [[Config getFirstBonus] isEqual:@"1"] &&
  423. ![PublicObj isUp] &&
  424. [YBYoungManager shareInstance].youngSwitch == 0) {
  425. [self firstLog];
  426. [Config saveFirstBonus:@"0"];
  427. }
  428. }
  429. } Fail:^(id fail) {
  430. }];
  431. }
  432. -(void)firstLog{
  433. firstLV = [[Loginbonus alloc]initWithFrame:CGRectMake(0, 0, _window_width, _window_height)AndNSArray:bonus_list AndDay:bonus_day andDayCount:dayCount andIsBonus:is_bonus];
  434. firstLV.delegate = self;
  435. [self.view addSubview:firstLV];
  436. }
  437. #pragma mark - 代理 动画结束释放空视图
  438. -(void)removeView:(NSDictionary*)dic{
  439. [firstLV removeFromSuperview];
  440. firstLV = nil;
  441. }
  442. -(void)startPlayerVideo {
  443. @weakify(self)
  444. [self.collectionView zf_filterShouldPlayCellWhileScrolled:^(NSIndexPath *indexPath) {
  445. @strongify(self)
  446. [self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
  447. }];
  448. }
  449. - (void)viewWillDisappear:(BOOL)animated {
  450. [super viewWillDisappear:animated];
  451. [[NSUserDefaults standardUserDefaults]setObject:@"0" forKey:@"show_share_pop"];
  452. [IQKeyboardManager sharedManager].enable = YES;
  453. _controlView.isDisappear = YES;
  454. NSLog(@"=====home:%lu",(unsigned long)self.player.currentPlayerManager.playState);
  455. // [self timerPause];
  456. [[YBHomeRedObj redInstance]timerPause];
  457. ///播放离开回来继续播放,暂停离开回来还是暂停状态-start
  458. if (self.player.currentPlayerManager.playState == 1) {
  459. _playerLeaveState = RKLeaveState_Playing;
  460. [_controlView controlSingleTapped];
  461. }else if (self.player.currentPlayerManager.playState == 2){
  462. _playerLeaveState = RKLeaveState_Pause;
  463. }else {
  464. [self.player stopCurrentPlayingCell];
  465. }
  466. ///播放离开回来继续播放,暂停离开回来还是暂停状态-end
  467. [self.controlView.zfVolumeView addSystemVolumeView];
  468. //停止动画
  469. [self.playingCell stopMusicAnimation:_videoList[self.player.playingIndexPath.row]];
  470. [[YBDayTaskManager shareInstance]taskOfWatchVideoEnd];
  471. }
  472. #pragma mark - private method
  473. -(void)pullData{
  474. if (_isLoadingMore || [PublicObj checkNull:minstr(_sourceBaseUrl)]) {
  475. [MBProgressHUD hideHUD];
  476. if ([PublicObj checkNull:minstr(_sourceBaseUrl)]) {
  477. [self startPlayerVideo];
  478. }
  479. return;
  480. }
  481. NSString *url = [NSString stringWithFormat:@"%@&p=%@",_sourceBaseUrl,@(_pages)];
  482. if ([url containsString:@"Video.getRecommendVideos"]) {
  483. //是首页推荐 url 添加 isstart 并且当 _pages>1 时更改状态为0
  484. if (_pages>1) {
  485. [common saveIsStart:@"0"];
  486. }
  487. url = [url stringByAppendingFormat:@"&isstart=%@",[common getIsStart]];
  488. }
  489. YBWeakSelf;
  490. _isLoadingMore = YES;
  491. [YBNetworking postWithUrl:url Dic:nil Suc:^(int code, id info, NSString *msg) {
  492. [MBProgressHUD hideHUD];
  493. _isLoadingMore = NO;
  494. if (code == 0) {
  495. NSArray *infoA = @[];
  496. if ([info isKindOfClass:[NSArray class]]) {
  497. infoA = [NSArray arrayWithArray:info];
  498. }
  499. if ([_fromWhere isEqual:@"YBTakeSameVideoVC"]) {
  500. //注意拍摄同款的视频列表在info[0]里边的videolist
  501. NSDictionary *infoDic = [info firstObject];
  502. infoA = [NSArray arrayWithArray:[infoDic valueForKey:@"videolist"]];
  503. }
  504. if ([_fromWhere isEqual:@"topicDetailsVC"]) {
  505. //注意标签的视频列表在info[0]里边的list
  506. NSDictionary *infoDic = [info firstObject];
  507. infoA = [NSArray arrayWithArray:[infoDic valueForKey:@"list"]];
  508. }
  509. if ([_fromWhere isEqual:@"YBCreActListView"]) {
  510. //注意活动的视频列表在info[0]里边的join_videos
  511. NSDictionary *infoDic = [info firstObject];
  512. infoA = [NSArray arrayWithArray:[infoDic valueForKey:@"join_videos"]];
  513. }
  514. if (_pages==1) {
  515. [_videoList removeAllObjects];
  516. }
  517. [_videoList addObjectsFromArray:infoA];
  518. if (_videoList.count<=0) {
  519. [PublicView showTextNoData:_collectionView text1:@"" text2:YZMsg(@"暂无推荐视频哦~") centerY:0.8];
  520. }else {
  521. [PublicView hiddenTextNoData:_collectionView];
  522. }
  523. [_videoUrls removeAllObjects];
  524. NSLog(@"beginTime-----:%@",[self getNowTimeTimestamp3]);
  525. for (NSDictionary *subDic in _videoList) {
  526. NSString *videoUrl = minstr([subDic valueForKey:@"href"]);
  527. [_videoUrls addObject:[NSURL URLWithString:[PublicObj decrypt:videoUrl]]];
  528. NSLog(@"当前完成-----:%@",[self getNowTimeTimestamp3]);
  529. }
  530. NSLog(@"endTime-----:%@",[self getNowTimeTimestamp3]);
  531. weakSelf.player.assetURLs = _videoUrls;
  532. [weakSelf.collectionView reloadData];
  533. //准备播放
  534. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  535. [weakSelf startPlayerVideo];
  536. _isHome = NO;
  537. });
  538. if (_isDoubleClickRefresh == YES) {
  539. _isDoubleClickRefresh = NO;
  540. [MBProgressHUD showPop:YZMsg(@"刷新成功")];
  541. }
  542. }else{
  543. [MBProgressHUD hideHUD];
  544. _isLoadingMore = NO;
  545. [MBProgressHUD showPop:msg];
  546. }
  547. } Fail:^(id fail) {
  548. [MBProgressHUD hideHUD];
  549. _isLoadingMore = NO;
  550. }];
  551. }
  552. -(NSString *)getNowTimeTimestamp3{
  553. NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
  554. // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
  555. [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss.SSSSSS"];
  556. //现在时间,你可以输出来看下是什么格式
  557. NSDate *datenow = [NSDate date];
  558. //----------将nsdate按formatter格式转成nsstring
  559. NSString *currentTimeString = [formatter stringFromDate:datenow];
  560. return currentTimeString;
  561. }
  562. #pragma mark - 播放
  563. /// play the video
  564. - (void)playTheVideoAtIndexPath:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
  565. /*
  566. if (_lastPlayCellIndex != -1) {
  567. YBLookVideoCell *lastCell = (YBLookVideoCell*)[_collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:_lastPlayCellIndex inSection:0]];
  568. [lastCell releaseObj:_videoList[_lastPlayCellIndex]];
  569. //上一个结束动画
  570. [lastCell stopMusicAnimation:_videoList[_lastPlayCellIndex]];
  571. NSLog(@"playtime:%f",self.player.currentTime);
  572. }
  573. NSLog(@"last:%d==cure:%ld",_lastPlayCellIndex,(long)indexPath.row);
  574. */
  575. _lastPlayCellIndex = (int)indexPath.row;
  576. YBLookVideoCell *currentCell = (YBLookVideoCell*)[_collectionView cellForItemAtIndexPath:indexPath];
  577. [currentCell checkLiveOrAdState:_videoList[indexPath.row]];
  578. //当前的开始动画
  579. [currentCell startMusicAnimation:_videoList[indexPath.row]];
  580. _currentVideoDic = _videoList[indexPath.row];
  581. _videoID = minstr([_currentVideoDic valueForKey:@"id"]);
  582. NSDictionary *userInfo = [_currentVideoDic valueForKey:@"userinfo"];
  583. _hostID = minstr([userInfo valueForKey:@"id"]);
  584. if (_commentTool) {
  585. [_commentTool hiddenEmojiOrKeyBoard];
  586. _commentTool.player = self.player;
  587. _commentTool.videoid = _videoID;
  588. _commentTool.hostid = _hostID;
  589. [_commentTool resetToolState];
  590. }
  591. //[self.player playTheIndexPath:indexPath scrollToTop:scrollToTop];
  592. [self.player playTheIndexPath:indexPath scrollPosition:scrollToTop animated:NO];
  593. [self.controlView resetControlView];
  594. //player-contentMode
  595. CGFloat coverRatio = 1.78;
  596. if (![PublicObj checkNull:minstr([_currentVideoDic valueForKey:@"anyway"])]) {
  597. coverRatio = [minstr([_currentVideoDic valueForKey:@"anyway"]) floatValue];
  598. }
  599. UIViewContentMode imageMode;
  600. if (coverRatio > 1) {
  601. imageMode = UIViewContentModeScaleAspectFill;
  602. } else {
  603. imageMode = UIViewContentModeScaleAspectFit;
  604. }
  605. [self.controlView showCoverViewWithUrl:minstr([_currentVideoDic valueForKey:@"thumb"]) withImageMode:imageMode];
  606. [self.fullControlView showTitle:@"" coverURLString:minstr([_currentVideoDic valueForKey:@"thumb"]) fullScreenMode:ZFFullScreenModeLandscape];
  607. self.fullControlView.playDoc = _currentVideoDic;
  608. /*
  609. @weakify(self);
  610. [PublicObj getThumbSizeWithUrl:minstr([_currentVideoDic valueForKey:@"thumb"]) complete:^(CGFloat width, CGFloat height) {
  611. @strongify(self);
  612. UIViewContentMode imageMode;
  613. if (width >= height) {
  614. imageMode = UIViewContentModeScaleAspectFit;
  615. } else {
  616. imageMode = UIViewContentModeScaleAspectFill;
  617. }
  618. [self.controlView showCoverViewWithUrl:minstr([_currentVideoDic valueForKey:@"thumb"]) withImageMode:imageMode];
  619. }];
  620. */
  621. if (_needCheckLimit) {
  622. //获取播放权限等
  623. [self getVideo:indexPath scrollToTop:scrollToTop];
  624. }
  625. }
  626. -(void)getVideo:(NSIndexPath *)indexPath scrollToTop:(BOOL)scrollToTop {
  627. if (_controlView.currentVol>0) {
  628. [_controlView videoMuted:YES];
  629. }
  630. YBWeakSelf;
  631. [YBNetworking postWithUrl:@"Video.getVideo" Dic:@{@"videoid":_videoID,@"mobileid":[PublicObj getDeviceUUID]} Suc:^(int code, id info, NSString *msg) {
  632. if (code == 0) {
  633. _needCheckLimit = NO;
  634. _currentVideoDic = [info firstObject];
  635. if (_controlView.currentVol>0) {
  636. [_controlView videoMuted:NO];
  637. }
  638. //默默替换点赞、评论、分享等数据 (不要给currentCell.dataDic重新赋值,数据会闪动,体验不好)
  639. if ([_currentVideoDic isKindOfClass:[NSDictionary class]]&&_videoList.count>indexPath.row) {
  640. [_videoList replaceObjectAtIndex:indexPath.row withObject:_currentVideoDic];
  641. }
  642. YBLookVideoCell *currentCell = (YBLookVideoCell*)[_collectionView cellForItemAtIndexPath:indexPath];
  643. if ([[Config getOwnID] isEqual:_hostID] || [[_currentVideoDic valueForKey:@"isattent"] isEqual:@"1"]) {
  644. currentCell.followBtn.hidden = YES;
  645. }else{
  646. [currentCell.followBtn setImage:[UIImage imageNamed:@"home_follow"] forState:0];
  647. currentCell.followBtn.hidden = NO;
  648. }
  649. // 青少年模式受限
  650. if ([YBYoungManager shareInstance].youngBan == 1) {
  651. [_controlView showPlayBtn];
  652. }
  653. }
  654. // else if (code == 1001){
  655. // //需要登录
  656. // [PublicObj warnLogin];
  657. // }
  658. // else if (code == 1000){
  659. // //游客次数限制 弹窗模式,
  660. // [weakSelf limitPlayVideo:-1 andMsg:msg];
  661. // }
  662. else if(code == 1002){
  663. //需要开通Vip
  664. [weakSelf limitPlayVideo:1 andMsg:msg];
  665. }else if (code == 1003){
  666. //需要支付
  667. [weakSelf limitPlayVideo:2 andMsg:msg];
  668. }else {
  669. _needCheckLimit = YES;
  670. [_controlView showPlayBtn];
  671. [MBProgressHUD showPop:msg];
  672. }
  673. } Fail:nil];
  674. }
  675. -(void)limitPlayVideo:(int)limiteType andMsg:(NSString *)msg{
  676. _needCheckLimit = YES;
  677. [_controlView showPlayBtn];
  678. //limiteType -1 游客 1:vip 2:pay
  679. YBWeakSelf;
  680. NSDictionary *contentDic = @{@"title":@"",@"msg":msg,@"left":YZMsg(@"取消"),@"right":(limiteType==1)?YZMsg(@"开通会员"):YZMsg(@"观看")};
  681. if (limiteType == -1) {
  682. contentDic = @{@"title":@"",@"msg":msg,@"left":@"",@"right":YZMsg(@"确认")};
  683. }
  684. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  685. if (eventType == 1) {
  686. if ([[Config getOwnID] intValue]<=0) {
  687. [PublicObj warnLogin];
  688. return;
  689. }
  690. if ([YBYoungManager shareInstance].youngSwitch == 1) {
  691. [MBProgressHUD showError:YZMsg(@"青少年模式下不支持该功能")];
  692. return;
  693. }
  694. //确认按钮
  695. if (limiteType == 1) {
  696. //vip
  697. YBVipVC *vipVC = [[YBVipVC alloc]init];
  698. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:vipVC animated:YES];
  699. }else if(limiteType == 2) {
  700. //付费观看
  701. [weakSelf goPay];
  702. }
  703. }
  704. }];
  705. }
  706. #pragma mark -
  707. -(void)goPay {
  708. YBWeakSelf;
  709. [MBProgressHUD showMessage:@""];
  710. [YBNetworking postWithUrl:@"Video.setVideoPay" Dic:@{@"videoid":_videoID} Suc:^(int code, id info, NSString *msg) {
  711. [MBProgressHUD hideHUD];
  712. if (code == 0) {
  713. [MBProgressHUD showPop:msg];
  714. _needCheckLimit = NO;
  715. [_controlView hiddenPlayBtn];
  716. }else if (code == 1004){
  717. //余额不足
  718. [weakSelf noMoney:msg];
  719. }else {
  720. [MBProgressHUD showPop:msg];
  721. }
  722. } Fail:^(id fail) {
  723. [MBProgressHUD hideHUD];
  724. }];
  725. }
  726. //余额不足提示
  727. -(void)noMoney:(NSString *)msg {
  728. NSDictionary *contentDic = @{@"title":@"",@"msg":msg,@"left":YZMsg(@"取消"),@"right":YZMsg(@"去充值")};
  729. [YBAlertView showAlertView:contentDic complete:^(int eventType) {
  730. if (eventType == 1) {
  731. //确认按钮
  732. YBRechargeVC *chargeVC = [[YBRechargeVC alloc]init];
  733. [[YBBaseAppDelegate sharedAppDelegate]pushViewController:chargeVC animated:YES];
  734. }
  735. }];
  736. }
  737. #pragma mark - UIScrollViewDelegate 列表播放必须实现
  738. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  739. [scrollView zf_scrollViewDidEndDecelerating];
  740. }
  741. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
  742. [scrollView zf_scrollViewDidEndDraggingWillDecelerate:decelerate];
  743. if (!decelerate) {
  744. if (self.player.currentPlayIndex == 0 ) {
  745. [MBProgressHUD showPop:YZMsg(@"已经到顶了哦")];
  746. }
  747. if (self.player.currentPlayIndex+1 == _videoList.count) {
  748. [MBProgressHUD showPop:YZMsg(@"没有更多视频")];
  749. }
  750. }
  751. }
  752. - (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
  753. [scrollView zf_scrollViewDidScrollToTop];
  754. }
  755. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  756. [scrollView zf_scrollViewDidScroll];
  757. }
  758. - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
  759. [scrollView zf_scrollViewWillBeginDragging];
  760. lastContenOffset = scrollView.contentOffset.y;
  761. // [self.player stopCurrentPlayingCell];
  762. }
  763. #pragma mark UICollectionViewDataSource
  764. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  765. return _videoList.count;
  766. }
  767. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  768. YBLookVideoCell *cell = (YBLookVideoCell *)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
  769. cell.player = self.player;
  770. cell.fromWhere = _fromWhere;
  771. cell.dataDic = _videoList[indexPath.row];
  772. YBWeakSelf;
  773. cell.videoCellEvent = ^(NSString *eventType, NSDictionary *eventDic) {
  774. [weakSelf cellBlockBack:eventType andInfo:eventDic andIndex:indexPath];
  775. };
  776. // if ([YBYoungManager shareInstance].youngSwitch == 1) {
  777. // cell.giftBtn.hidden = YES;
  778. // }else{
  779. // cell.giftBtn.hidden = NO;
  780. // }
  781. //
  782. return cell;
  783. }
  784. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  785. if (self.player.currentPlayIndex == indexPath.row) {
  786. return;
  787. }
  788. [self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
  789. }
  790. #pragma mark - 功能
  791. #pragma mark - cell block回调
  792. -(void)cellBlockBack:(NSString *)eventType andInfo:(NSDictionary *)eventDic andIndex:(NSIndexPath *)indexPath{
  793. if ([eventType isEqual:@"视频-打赏"]) {
  794. //视频打赏处理
  795. [_controlView showGift:eventDic];
  796. }else if([eventType isEqual:@"视频-删除"]){
  797. //删除事件特殊处理
  798. if (!_fromWhere) {
  799. //推荐删除
  800. [_videoList removeObjectAtIndex:indexPath.row];
  801. /* //如果个人主页也要求删除后显示下一个(向上、向下滑),将if条件去掉else语句去掉执行下列if
  802. if (_fromWhere) {
  803. [Config saveSignOfDelVideo:@"1"];
  804. if (_videoList.count==0) {
  805. [self.navigationController popViewControllerAnimated:YES];
  806. }
  807. }
  808. */
  809. [_videoUrls removeAllObjects];
  810. for (NSDictionary *subDic in _videoList) {
  811. NSString *videoUrl = minstr([subDic valueForKey:@"href"]);
  812. [_videoUrls addObject:[NSURL URLWithString:[PublicObj decrypt:videoUrl]]];
  813. }
  814. [self.player stopCurrentPlayingCell];
  815. if (indexPath.row == _videoList.count) {
  816. //说明删除的是最后一个
  817. int toIndex = ((int)indexPath.row-1) < 0 ? 0 : ((int)indexPath.row-1);
  818. indexPath = [NSIndexPath indexPathForRow:toIndex inSection:0];
  819. }
  820. [_collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionNone animated:NO];
  821. self.player.assetURLs = _videoUrls;
  822. [self.collectionView reloadData];
  823. //准备播放
  824. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  825. [self startPlayerVideo];
  826. });
  827. }else {
  828. //push页面删除
  829. [Config saveSignOfDelVideo:@"1"];
  830. [self.navigationController popViewControllerAnimated:YES];
  831. }
  832. }else if ([eventType isEqual:@"视频-静音"]) {
  833. //静音事件特殊处理
  834. [self voiceRecordOrPlayEvent:eventDic];
  835. }else {
  836. //默默更新数据
  837. //视频-关注、视频-点赞、视频-评论
  838. NSMutableDictionary *m_dic = [NSMutableDictionary dictionaryWithDictionary:_videoList[indexPath.row]];
  839. [m_dic addEntriesFromDictionary:eventDic];
  840. [_videoList replaceObjectAtIndex:indexPath.row withObject:m_dic];
  841. _currentVideoDic = [NSDictionary dictionaryWithDictionary:m_dic];
  842. }
  843. }
  844. -(void)voiceRecordOrPlayEvent:(NSDictionary *)videoStateDic {
  845. int muteType = [minstr([videoStateDic valueForKey:@"mutedType"]) intValue];
  846. int playState = [minstr([videoStateDic valueForKey:@"playState"]) intValue];
  847. // [_controlView videoMuted:muteType];
  848. if (muteType == 0 && self.player.currentPlayerManager.isPlaying) {
  849. return;
  850. }
  851. if (playState == ZFPlayerPlayStatePlaying) {
  852. [_controlView controlSingleTapped];
  853. }
  854. //rk_解决语音评论导致声音问题
  855. if (muteType == 0) {
  856. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
  857. [[AVAudioSession sharedInstance] setActive:YES error:nil];
  858. }
  859. }
  860. #pragma mark - 视频开始观看-结束观看
  861. -(void)videoStart {
  862. if ([_hostID isEqual:[Config getOwnID]] || [[Config getOwnID] intValue] <= 0) {
  863. return;
  864. }
  865. NSString *random_str = [PublicObj stringToMD5:[NSString stringWithFormat:@"%@-%@-#2hgfk85cm23mk58vncsark",[Config getOwnID],_videoID]];
  866. [YBNetworking postWithUrl:@"Video.addView" Dic:@{@"videoid":_videoID,@"random_str":random_str} Suc:^(int code, id info, NSString *msg) {
  867. NSLog(@"addview-%d-%@-%@",code,info,msg);
  868. } Fail:nil];
  869. }
  870. -(void)videoEnd {
  871. if ([_hostID isEqual:[Config getOwnID]] || [[Config getOwnID] intValue] <= 0) {
  872. return;
  873. }
  874. NSString *random_str = [PublicObj stringToMD5:[NSString stringWithFormat:@"%@-%@-#2hgfk85cm23mk58vncsark",[Config getOwnID],_videoID]];
  875. [YBNetworking postWithUrl:@"Video.setConversion" Dic:@{@"videoid":_videoID,@"random_str":random_str} Suc:^(int code, id info, NSString *msg) {
  876. NSLog(@"setConversion-%d-%@-%@",code,info,msg);
  877. } Fail:nil];
  878. }
  879. #pragma mark - 增加观看时间
  880. - (void)addLookTimeForToday:(NSString *)length{
  881. if ([length isEqual:@"0"] || [[Config getOwnID] intValue]<0 || [_hostID isEqual:[Config getOwnID]]) {
  882. return;
  883. }
  884. NSMutableDictionary *mudic = @{
  885. @"uid":[Config getOwnID],
  886. @"token":[Config getOwnToken],
  887. @"length":length
  888. }.mutableCopy;
  889. [mudic setObject:[PublicObj sortString:mudic] forKey:@"sign"];
  890. [YBNetworking postWithUrl:@"Agent.setViewLength" Dic:mudic Suc:^(int code, id info, NSString *msg) {
  891. NSLog(@"增加时间------------------%@",length);
  892. } Fail:^(id fail) {
  893. }];
  894. }
  895. #pragma mark - set/get
  896. - (UICollectionView *)collectionView {
  897. if (!_collectionView) {
  898. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  899. CGFloat itemWidth = self.view.frame.size.width;
  900. CGFloat itemHeight = self.view.frame.size.height;
  901. layout.itemSize = CGSizeMake(itemWidth, itemHeight);
  902. layout.sectionInset = UIEdgeInsetsZero;
  903. layout.minimumLineSpacing = 0;
  904. layout.minimumInteritemSpacing = 0;
  905. if (self.scrollViewDirection == ZFPlayerScrollViewDirectionVertical) {
  906. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  907. } else if (self.scrollViewDirection == ZFPlayerScrollViewDirectionHorizontal) {
  908. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  909. }
  910. _collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];
  911. _collectionView.delegate = self;
  912. _collectionView.dataSource = self;
  913. _collectionView.backgroundColor = Normal_Color;
  914. /// 横向滚动 这行代码必须写
  915. _collectionView.zf_scrollViewDirection = self.scrollViewDirection;
  916. [_collectionView registerClass:[YBLookVideoCell class] forCellWithReuseIdentifier:reuseIdentifier];
  917. _collectionView.pagingEnabled = YES;
  918. _collectionView.showsVerticalScrollIndicator = NO;
  919. _collectionView.showsHorizontalScrollIndicator = NO;
  920. _collectionView.scrollsToTop = NO;
  921. _collectionView.bounces = NO;
  922. _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  923. /*
  924. /// 停止的时候找出最合适的播放
  925. @weakify(self)
  926. _collectionView.zf_scrollViewDidStopScrollCallback = ^(NSIndexPath * _Nonnull indexPath) {
  927. @strongify(self)
  928. if (self.player.playingIndexPath) return;
  929. if (indexPath.row + 1 >= _videoList.count) {
  930. /// 加载下一页数据
  931. _pages += 1;
  932. [MBProgressHUD showMessage:@""];
  933. [self pullData];
  934. }else {
  935. [self playTheVideoAtIndexPath:indexPath scrollToTop:NO];
  936. }
  937. };
  938. */
  939. }
  940. return _collectionView;
  941. }
  942. - (YBVideoControlView *)controlView {
  943. if (!_controlView) {
  944. _controlView = [YBVideoControlView new];
  945. @weakify(self);
  946. _controlView.ybContorEvent = ^(NSString *eventStr, ZFPlayerGestureControl *gesControl) {
  947. @strongify(self);
  948. [self contorEvent:eventStr andGes:gesControl];
  949. };
  950. }
  951. return _controlView;
  952. }
  953. -(void)contorEvent:(NSString *)eventStr andGes:(ZFPlayerGestureControl*)gesControl{
  954. if (_commentTool && _commentTool.isPrepareEditing) {
  955. [_commentTool hiddenEmojiOrKeyBoard];
  956. return;
  957. }
  958. if ([eventStr isEqual:@"控制-单击"]) {
  959. if (_needCheckLimit) {
  960. //获取播放权限等
  961. [self getVideo:self.player.playingIndexPath scrollToTop:NO];
  962. }else {
  963. [_controlView controlSingleTapped];
  964. }
  965. }
  966. if ([eventStr isEqual:@"控制-双击"]) {
  967. // if ([[Config getOwnID] intValue]<=0 && [Config getTranslate]) {
  968. // return;
  969. // }
  970. if (_videoList.count<=0) {
  971. return;
  972. }
  973. if ([[Config getOwnID] intValue]<=0) {
  974. [PublicObj warnLogin];
  975. return;
  976. }
  977. NSString *isLike = minstr([_currentVideoDic valueForKey:@"islike"]);
  978. CGPoint center = [gesControl.doubleTap locationInView:self.controlView];
  979. [PublicObj doubleClickShowZan:self.controlView withCenter:center];
  980. //rk_2-23 双击对作品赞,双击不取消赞
  981. if ([isLike isEqual:@"0"]) {
  982. [self.playingCell clickLikeBtn];
  983. }
  984. }
  985. if ([eventStr isEqual:@"控制-主页"]) {
  986. [self.playingCell swipGesGoHome];
  987. }
  988. }
  989. - (UIButton *)backBtn {
  990. if (!_backBtn) {
  991. _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  992. _backBtn.frame = CGRectMake(0, 24+statusbarHeight, 40, 40);
  993. [_backBtn setImage:[UIImage imageNamed:@"pub_back"] forState:UIControlStateNormal];
  994. [_backBtn addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
  995. }
  996. return _backBtn;
  997. }
  998. - (void)backClick:(UIButton *)sender {
  999. [self addLookTimeForToday:[NSString stringWithFormat:@"%.0f",self.player.currentTime]];
  1000. if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"yb_dsp_reset"]isEqual:@"1"]) {
  1001. [[NSUserDefaults standardUserDefaults]setObject:@"0" forKey:@"yb_dsp_reset"];
  1002. [PublicObj resetVC:[[YBTabBarController alloc]initWithAlert:NO]];
  1003. }else {
  1004. [self.navigationController popViewControllerAnimated:YES];
  1005. }
  1006. }
  1007. - (YBCommentToolBar *)commentTool {
  1008. YBWeakSelf;
  1009. if (!_commentTool) {
  1010. _commentTool = [[YBCommentToolBar alloc]initWithFrame:CGRectMake(0,_window_height - 50-ShowDiff, _window_width, 50+ShowDiff) andVCType:0 superView:self.view];
  1011. _commentTool.backgroundColor = RGB_COLOR(@"#201C36", 0.2);
  1012. _commentTool.comToolEvent = ^(NSString *eventType, NSDictionary *eventDic) {
  1013. [weakSelf commentToolCallBack:eventType andEventDic:eventDic];
  1014. };
  1015. }
  1016. return _commentTool;
  1017. }
  1018. -(void)commentToolCallBack:(NSString *)eventType andEventDic:(NSDictionary *)eventDic {
  1019. if ([eventType isEqual:@"工具-游客"]) {
  1020. [PublicObj warnLogin];
  1021. }
  1022. if ([eventType isEqual:@"工具-评论"]) {
  1023. NSString *nums = minstr([eventDic valueForKey:@"comments"]);
  1024. [self.playingCell updateCommentNums:nums];
  1025. }
  1026. if ([eventType isEqual:@"工具-录音"]) {
  1027. [self voiceRecordOrPlayEvent:eventDic];
  1028. }
  1029. }
  1030. - (YBLookVideoCell *)playingCell {
  1031. // if (!_playingCell) {
  1032. _playingCell = (YBLookVideoCell*)[_collectionView cellForItemAtIndexPath:self.player.playingIndexPath];
  1033. // }
  1034. return _playingCell;
  1035. }
  1036. #pragma mark - 通知
  1037. -(void)addNotifications {
  1038. [[NSNotificationCenter defaultCenter]removeObserver:self];
  1039. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
  1040. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
  1041. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
  1042. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)name:UIKeyboardWillHideNotification object:nil];
  1043. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadProNot:)name:@"uploadProNot" object:nil];
  1044. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(uploadCoverNot:)name:@"uploadCoverNot" object:nil];
  1045. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youngModelTimeEnd:) name:ybYoungModelTimeEndEvent object:nil];
  1046. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(youngSiwtchOpen) name:ybYoungModelSwitchChage object:nil];
  1047. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(timeGo) name:@"lookCountGo" object:nil];
  1048. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(showHomeVideoRed) name:@"showHomeVideoRed" object:nil];
  1049. [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideHomeVideoRed) name:@"hideHomeVideoRed" object:nil];
  1050. // [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(hideBottomFunBtn) name:@"hideBottomFunBtn" object:nil];
  1051. }
  1052. //-(void)hideBottomFunBtn{
  1053. // _normalBtn.hidden = YES;
  1054. //}
  1055. -(void)youngSiwtchOpen {
  1056. if (firstLV) {
  1057. [self removeView:@{}];
  1058. }
  1059. }
  1060. -(void)youngModelTimeEnd:(NSNotification *)not {
  1061. [_controlView showPlayBtn];
  1062. }
  1063. -(void)ctrUpdateVideoInfo {
  1064. if ([[NSUserDefaults standardUserDefaults] objectForKey:@"yb_update_video_on_other"]){
  1065. NSDictionary *newDic = [[NSUserDefaults standardUserDefaults]objectForKey:@"yb_update_video_on_other"];
  1066. if ([[_currentVideoDic valueForKey:@"id"] isEqual:[newDic valueForKey:@"id"]] && self.playingCell) {
  1067. [self.playingCell noticeUpdateUI:newDic];
  1068. [_videoList replaceObjectAtIndex:self.player.currentPlayIndex withObject:newDic];
  1069. }
  1070. }
  1071. }
  1072. #pragma mark - 前后台
  1073. -(void)onAppDidEnterBackground {
  1074. // [self timerPause];
  1075. [[YBHomeRedObj redInstance]timerPause];
  1076. //停止动画
  1077. [self.playingCell stopMusicAnimation:_videoList[self.player.playingIndexPath.row]];
  1078. [self.playingCell releaseObj:self.videoList[self.player.playingIndexPath.row] isBackGround:YES];
  1079. [self uploadViewBackgroundOrForegroundCtr:YES];
  1080. }
  1081. -(void)onAppWillEnterForeground {
  1082. // [self timerBegin];
  1083. [[YBHomeRedObj redInstance]timerBegin];
  1084. //当前的开始动画
  1085. [self.playingCell startMusicAnimation:_videoList[self.player.playingIndexPath.row]];
  1086. [self.playingCell checkLiveOrAdState:_videoList[self.player.playingIndexPath.row]];
  1087. [self uploadViewBackgroundOrForegroundCtr:NO];
  1088. }
  1089. - (void)keyboardWillShow:(NSNotification *)aNotification {
  1090. //获取键盘的高度
  1091. NSDictionary *userInfo = [aNotification userInfo];
  1092. NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
  1093. CGRect keyboardRect = [aValue CGRectValue];
  1094. CGFloat height = keyboardRect.origin.y;
  1095. if (_commentTool) {
  1096. _commentTool.isPrepareEditing = YES;
  1097. _commentTool.faceBtn.selected = NO;
  1098. _commentTool.frame = CGRectMake(0, height - 50, _window_width, 50);
  1099. _commentTool.emojiV.frame = CGRectMake(0, _window_height, _window_width, EmojiHeight+ShowDiff);
  1100. }
  1101. }
  1102. - (void)keyboardWillHide:(NSNotification *)aNotification {
  1103. //键盘消失一定要判断 faceBtn.selected 状态
  1104. if (_commentTool && _commentTool.faceBtn.selected == NO) {
  1105. [_commentTool hiddenEmojiOrKeyBoard];
  1106. _commentTool.isPrepareEditing = NO;
  1107. }
  1108. }
  1109. -(void)uploadProNot:(NSNotification *)aNotification {
  1110. CGFloat notiPro = [aNotification.object floatValue];
  1111. self.uploadProgress = notiPro;
  1112. }
  1113. -(void)uploadCoverNot:(NSNotification *)aNotification {
  1114. UIImage *notiCover = (UIImage *)aNotification.object;
  1115. self.uploadCover = notiCover;
  1116. }
  1117. - (void)dealloc {
  1118. [[NSNotificationCenter defaultCenter]removeObserver:self];
  1119. }
  1120. #pragma mark - 转屏和状态栏
  1121. //- (BOOL)shouldAutorotate {
  1122. // return NO;
  1123. //}
  1124. //- (UIStatusBarStyle)preferredStatusBarStyle {
  1125. // return UIStatusBarStyleLightContent;
  1126. //}
  1127. //- (BOOL)prefersStatusBarHidden {
  1128. // return NO;
  1129. //}
  1130. - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
  1131. return UIStatusBarAnimationSlide;
  1132. }
  1133. #pragma mark - 视频上传进度 s
  1134. - (YBUploadProgress *)uploadView {
  1135. if (!_uploadView) {
  1136. CGFloat _www = _window_width*0.2;
  1137. CGFloat _hhh = _www*4/3;
  1138. _uploadView = [[YBUploadProgress alloc]initWithFrame:CGRectMake(10, 74+statusbarHeight, _www, _hhh)];
  1139. _uploadView.hidden = YES;
  1140. }
  1141. return _uploadView;;
  1142. }
  1143. - (void)setUploadProgress:(CGFloat)uploadProgress{
  1144. dispatch_async(dispatch_get_main_queue(), ^{
  1145. _uploadProgress = uploadProgress;
  1146. UIApplicationState state = [UIApplication sharedApplication].applicationState;
  1147. if (state == UIApplicationStateActive){
  1148. _uploadView.progress = _uploadProgress;
  1149. if (_uploadProgress >= 1) {
  1150. _uploadView.hidden = YES;
  1151. if (_videoList.count<=0) {
  1152. [self doubleClickRefreshForYou];
  1153. _isDoubleClickRefresh = NO;
  1154. }
  1155. }
  1156. }
  1157. });
  1158. }
  1159. - (void)setUploadCover:(UIImage *)uploadCover{
  1160. dispatch_async(dispatch_get_main_queue(), ^{
  1161. _uploadCover = uploadCover;
  1162. UIApplicationState state = [UIApplication sharedApplication].applicationState;
  1163. if (state == UIApplicationStateActive){
  1164. _uploadView.hidden = NO;
  1165. _uploadView.proImg = _uploadCover;
  1166. }
  1167. });
  1168. }
  1169. -(void)uploadViewBackgroundOrForegroundCtr:(BOOL)isBack {
  1170. AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
  1171. if (0 < app.allUploadPro && app.allUploadPro < 1 && isBack == NO) {
  1172. _uploadView.hidden = NO;
  1173. }else{
  1174. _uploadView.hidden = YES;
  1175. if (_videoList.count<=0) {
  1176. [self doubleClickRefreshForYou];
  1177. _isDoubleClickRefresh = NO;
  1178. }
  1179. }
  1180. }
  1181. #pragma mark - 视频上传进度 e
  1182. - (ZFCustomControlView *)fullControlView {
  1183. if (!_fullControlView) {
  1184. YBWeakSelf;
  1185. _fullControlView = [[ZFCustomControlView alloc] init];
  1186. _fullControlView.player = self.player;
  1187. _fullControlView.bottomEvent = ^(NSString *str) {
  1188. if([str isEqual:@"关闭评论"]){
  1189. [[NSNotificationCenter defaultCenter]postNotificationName:UIKeyboardWillHideNotification object:nil];
  1190. }
  1191. };
  1192. }
  1193. return _fullControlView;
  1194. }
  1195. @end