HMVideoView.m 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334
  1. //
  2. // HMVideoView.m
  3. // BuguLive
  4. //
  5. // Created by 范东 on 2018/12/27.
  6. // Copyright © 2018 xfg. All rights reserved.
  7. //
  8. #import "HMVideoView.h"
  9. #import "HMVideoPlayer.h"
  10. #import "HMCommentView.h"
  11. #import "HMShareView.h"
  12. #import "BGReportController.h"
  13. #import "FDUIKitObjC.h"
  14. #import "GiftView.h"
  15. #import "RechargeView.h"
  16. #import <LCActionSheet.h>
  17. #import "SVGAAnimationView.h"
  18. #import "BGVideoGiftAnimationView.h"
  19. #import "GifImageView.h"
  20. #import "MPersonCenterVC.h"
  21. #import "SSearchVC.h"
  22. #import <TXLiteAVSDK_Professional/TXVodPlayer.h>
  23. #import "HMVideoPlayerViewController.h"
  24. @interface HMVideoView ()<UIScrollViewDelegate, HMVideoPlayerDelegate, HMVideoControlViewDelegate,HMShareViewDelegate,GiftViewDelegate,SVGAAnimationViewDelegate,BGVideoGiftAnimationViewDelegate,GifImageViewDelegate>
  25. // 创建三个控制视图,用于滑动切换
  26. @property (nonatomic, strong) HMVideoControlView *topView; // 顶部视图
  27. @property (nonatomic, strong) HMVideoControlView *middleView; // 中间视图
  28. @property (nonatomic, strong) HMVideoControlView *bottomView; // 底部视图
  29. // 控制播放的索引,不完全等于当前播放内容的索引
  30. @property (nonatomic, assign) NSInteger index;
  31. // 当前播放内容是索引
  32. @property (nonatomic, assign) NSInteger currentPlayIndex;
  33. @property (nonatomic, weak) UIViewController *vc;
  34. @property (nonatomic, assign) BOOL isPushed;
  35. @property (nonatomic, strong) NSMutableArray *videos;
  36. // 记录播放内容
  37. @property (nonatomic, copy) NSString *currentPlayId;
  38. // 记录滑动前的播放状态
  39. @property (nonatomic, assign) BOOL isPlaying_beforeScroll;
  40. @property (nonatomic, assign) BOOL isRefreshMore;
  41. @property (nonatomic, strong) NSMutableDictionary *shareDict;
  42. @property (nonatomic, strong) HMShareView *shareView;
  43. @property (nonatomic, assign) NSInteger currentDiamonds; // 当前账户钻石数量
  44. @property(nonatomic, assign) CGFloat giftViewHeight; // GiftView的高度
  45. @property (nonatomic, strong) NSDictionary *dict;
  46. @property(nonatomic, strong) SmallVideoListModel *currentModel;
  47. @property(nonatomic, strong) RechargeView *rechargeView;
  48. @property(nonatomic, strong) NSMutableArray *animationArray;
  49. @property(nonatomic, assign) BOOL isAnimated;
  50. @property(nonatomic, assign) BOOL isBigAnimated;
  51. @property(nonatomic, strong) SVGAAnimationView *animationView;
  52. //
  53. @property(nonatomic, strong) BGVideoGiftAnimationView *tipAnimationView;
  54. @property(nonatomic, strong) NSMutableArray *tipAnimationArray;
  55. //@property(nonatomic, assign) BOOL isTipAnimated;
  56. //
  57. @property(nonatomic, strong) GifImageView *gifImageView;
  58. //@property(nonatomic, strong) NSMutableArray *gifImageViewArray;
  59. //@property(nonatomic, assign) BOOL isGifAnimated;
  60. //我的按钮、搜索按钮
  61. @property(nonatomic, strong) UIButton *mineBtn;
  62. @property(nonatomic, strong) UIButton *searchBtn;
  63. @end
  64. @implementation HMVideoView
  65. /*
  66. // Only override drawRect: if you perform custom drawing.
  67. // An empty implementation adversely affects performance during animation.
  68. - (void)drawRect:(CGRect)rect {
  69. // Drawing code
  70. }
  71. */
  72. - (instancetype)initWithVC:(UIViewController *)vc isPushed:(BOOL)isPushed requestDict:(NSDictionary *)dict{
  73. if (self = [super init]) {
  74. self.vc = vc;
  75. self.isPushed = isPushed;
  76. self.dict = dict;
  77. self.backgroundColor = kClearColor;
  78. self.shareDict = [NSMutableDictionary dictionary];
  79. [self addSubview:self.scrollView];
  80. [self loadGiftView:[GiftListManager sharedInstance].giftMArray];
  81. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  82. make.edges.equalTo(self);
  83. }];
  84. [self addSubview:self.animationView];
  85. [self.animationView mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.edges.equalTo(self);
  87. }];
  88. [self performBlock:^(id selfPtr) {
  89. self.tipAnimationView.frame = CGRectMake(kScreenW, kScreenH / 4, 186, 38);
  90. } afterDelay:0.25];
  91. // self.topView.commentButton.hidden = !isPushed;
  92. // self.middleView.commentButton.hidden = !isPushed;
  93. // self.bottomView.commentButton.hidden = !isPushed;
  94. }
  95. return self;
  96. }
  97. - (void)setIsRecommend:(BOOL)isRecommend{
  98. _isRecommend = isRecommend;
  99. //不是Push来的就添加下拉刷新
  100. if (!self.isPushed) {
  101. __weak __typeof(self)weakSelf = self;
  102. [self.viewModel refreshNewListWithSuccess:^(NSArray * _Nonnull list) {
  103. __strong __typeof(weakSelf)strongSelf = weakSelf;
  104. [strongSelf setModels:list index:0];
  105. if (strongSelf.isRefreshVideoBlock) {
  106. strongSelf.isRefreshVideoBlock(YES);
  107. }
  108. } failure:^(NSError * _Nonnull error) {
  109. NSLog(@"%@", error);
  110. } WithRequestDict:self.dict];
  111. // 上下拉刷新
  112. MJRefreshGifHeader *header;
  113. header = [MJRefreshGifHeader headerWithRefreshingBlock:^{
  114. __strong __typeof(weakSelf)strongSelf = weakSelf;
  115. [strongSelf.videos removeAllObjects];
  116. __weak __typeof(self)weakSelf2 = strongSelf;
  117. [strongSelf.viewModel refreshNewListWithSuccess:^(NSArray * _Nonnull list) {
  118. __strong __typeof(weakSelf)strongSelf2 = weakSelf2;
  119. [strongSelf2 setModels:list index:0];
  120. [strongSelf2.scrollView.mj_header endRefreshing];
  121. if (list.count < 20) {
  122. [strongSelf2.scrollView.mj_footer endRefreshingWithNoMoreData];
  123. }else{
  124. [strongSelf2.scrollView.mj_footer endRefreshing];
  125. }
  126. } failure:^(NSError * _Nonnull error) {
  127. __strong __typeof(weakSelf)strongSelf2 = weakSelf2;
  128. NSLog(@"%@", error);
  129. [strongSelf2.scrollView.mj_header endRefreshing];
  130. [strongSelf2.scrollView.mj_footer endRefreshingWithNoMoreData];
  131. } WithRequestDict:self.dict];
  132. }];
  133. // 隐藏时间
  134. header.lastUpdatedTimeLabel.hidden = YES;
  135. // 隐藏状态
  136. header.stateLabel.hidden = YES;
  137. NSMutableArray *pullingImages = [NSMutableArray array];
  138. UIImage *image = [UIImage imageNamed:@"refresh_header_start"];
  139. [pullingImages addObject:image];
  140. UIImage *image2 = [UIImage imageNamed:@"refresh_header_start"];
  141. [pullingImages addObject:image2];
  142. NSArray *arrimg = [NSArray arrayWithObject:[pullingImages firstObject]];
  143. [header setImages:arrimg forState:MJRefreshStateIdle];
  144. NSArray *arrimg2 = [NSArray arrayWithObject:[pullingImages lastObject]];
  145. [header setImages:arrimg2 forState:MJRefreshStatePulling];
  146. NSMutableArray *progressImage = [NSMutableArray array];
  147. for (NSUInteger i = 1; i <= kRefreshImgCount; i++)
  148. {
  149. UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"refresh_header_%ld", i]];
  150. if (image)
  151. {
  152. [progressImage addObject:image];
  153. }
  154. }
  155. [header setImages:progressImage duration:0.04*progressImage.count forState:MJRefreshStateRefreshing];
  156. self.scrollView.mj_header = header;
  157. }
  158. self.scrollView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
  159. [self.player pausePlay];
  160. // 当播放索引为最后一个时才会触发下拉刷新
  161. self.currentPlayIndex = self.videos.count - 1;
  162. [self.viewModel refreshMoreListWithSuccess:^(NSArray * _Nonnull list) {
  163. self.isRefreshMore = NO;
  164. if (list) {
  165. // 处理数据不准问题
  166. [self addModels:list index:self.currentPlayIndex];
  167. [self.scrollView.mj_footer endRefreshing];
  168. if (list.count < 20) {
  169. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  170. }else{
  171. [self.scrollView.mj_footer endRefreshing];
  172. }
  173. }else {
  174. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  175. }
  176. } failure:^(NSError * _Nonnull error) {
  177. NSLog(@"%@", error);
  178. self.isRefreshMore = NO;
  179. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  180. } WithRequestDict:self.dict];
  181. }];
  182. }
  183. - (void)layoutSubviews {
  184. [super layoutSubviews];
  185. CGFloat controlW = CGRectGetWidth(self.scrollView.frame);
  186. CGFloat controlH = CGRectGetHeight(self.scrollView.frame);
  187. self.topView.frame = CGRectMake(0, 0, controlW, controlH);
  188. self.middleView.frame = CGRectMake(0, controlH, controlW, controlH);
  189. self.bottomView.frame = CGRectMake(0, 2 * controlH, controlW, controlH);
  190. }
  191. #pragma mark - Public Methods
  192. - (void)setModels:(NSArray *)models index:(NSInteger)index {
  193. if (models.count < 20) {
  194. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  195. }
  196. [self.videos removeAllObjects];
  197. NSMutableArray *tempArray = [NSMutableArray array];
  198. for (NSDictionary *dict in models)
  199. {
  200. SmallVideoListModel *model = [SmallVideoListModel mj_objectWithKeyValues:dict];
  201. [tempArray addObject:model];
  202. }
  203. [self.videos addObjectsFromArray:tempArray];
  204. self.index = index;
  205. self.currentPlayIndex = index;
  206. if (models.count == 0) return;
  207. self.currentModel = [models objectAtIndex:index];
  208. if (models.count == 1) {
  209. [self.middleView removeFromSuperview];
  210. [self.bottomView removeFromSuperview];
  211. self.scrollView.contentSize = CGSizeMake(0, kScreenH);
  212. self.topView.model = self.videos.firstObject;
  213. [self playVideoFrom:self.topView];
  214. }else if (models.count == 2) {
  215. [self.bottomView removeFromSuperview];
  216. self.scrollView.contentSize = CGSizeMake(0, kScreenH * 2);
  217. self.topView.model = self.videos.firstObject;
  218. self.middleView.model = self.videos.lastObject;
  219. if (index == 1) {
  220. self.scrollView.contentOffset = CGPointMake(0, kScreenH);
  221. [self playVideoFrom:self.middleView];
  222. }else {
  223. [self playVideoFrom:self.topView];
  224. }
  225. }else {
  226. if (index == 0) { // 如果是第一个,则显示上视图,且预加载中下视图
  227. self.topView.model = self.videos[index];
  228. self.middleView.model = self.videos[index + 1];
  229. self.bottomView.model = self.videos[index + 2];
  230. // 播放第一个
  231. [self playVideoFrom:self.topView];
  232. }else if (index == models.count - 1) { // 如果是最后一个,则显示最后视图,且预加载前两个
  233. self.bottomView.model = self.videos[index];
  234. self.middleView.model = self.videos[index - 1];
  235. self.topView.model = self.videos[index - 2];
  236. // 显示最后一个
  237. self.scrollView.contentOffset = CGPointMake(0, kScreenH * 2);
  238. // 播放最后一个
  239. [self playVideoFrom:self.bottomView];
  240. }else { // 显示中间,播放中间,预加载上下
  241. self.middleView.model = self.videos[index];
  242. self.topView.model = self.videos[index - 1];
  243. self.bottomView.model = self.videos[index + 1];
  244. // 显示中间
  245. self.scrollView.contentOffset = CGPointMake(0, kScreenH);
  246. // 播放中间
  247. [self playVideoFrom:self.middleView];
  248. }
  249. }
  250. }
  251. // 添加播放数据后,重置index,防止出现错位的情况
  252. - (void)addModels:(NSArray *)models index:(NSInteger)index {
  253. NSMutableArray *tempArray = [NSMutableArray array];
  254. for (NSDictionary *dict in models)
  255. {
  256. SmallVideoListModel *model = [SmallVideoListModel mj_objectWithKeyValues:dict];
  257. [tempArray addObject:model];
  258. }
  259. [self.videos addObjectsFromArray:tempArray];
  260. self.index = index;
  261. self.currentPlayIndex = index;
  262. if (self.videos.count == 0) return;
  263. if (self.videos.count == 1) {
  264. [self.middleView removeFromSuperview];
  265. [self.bottomView removeFromSuperview];
  266. self.scrollView.contentSize = CGSizeMake(0, kScreenH);
  267. self.topView.model = self.videos.firstObject;
  268. [self playVideoFrom:self.topView];
  269. }else if (self.videos.count == 2) {
  270. [self.bottomView removeFromSuperview];
  271. self.scrollView.contentSize = CGSizeMake(0, kScreenH * 2);
  272. self.topView.model = self.videos.firstObject;
  273. self.middleView.model = self.videos.lastObject;
  274. if (index == 1) {
  275. self.scrollView.contentOffset = CGPointMake(0, kScreenH);
  276. [self playVideoFrom:self.middleView];
  277. }else {
  278. [self playVideoFrom:self.topView];
  279. }
  280. }else {
  281. if (index == 0) { // 如果是第一个,则显示上视图,且预加载中下视图
  282. self.topView.model = self.videos[index];
  283. self.middleView.model = self.videos[index + 1];
  284. self.bottomView.model = self.videos[index + 2];
  285. // 播放第一个
  286. [self playVideoFrom:self.topView];
  287. }else if (index == self.videos.count - 1) { // 如果是最后一个,则显示最后视图,且预加载前两个
  288. self.bottomView.model = self.videos[index];
  289. self.middleView.model = self.videos[index - 1];
  290. self.topView.model = self.videos[index - 2];
  291. // 显示最后一个
  292. self.scrollView.contentOffset = CGPointMake(0, kScreenH * 2);
  293. // 播放最后一个
  294. [self playVideoFrom:self.bottomView];
  295. }else { // 显示中间,播放中间,预加载上下
  296. self.middleView.model = self.videos[index];
  297. self.topView.model = self.videos[index - 1];
  298. self.bottomView.model = self.videos[index + 1];
  299. // 显示中间
  300. self.scrollView.contentOffset = CGPointMake(0, kScreenH);
  301. // 播放中间
  302. [self playVideoFrom:self.middleView];
  303. }
  304. }
  305. }
  306. - (void)pause {
  307. if (self.player.isPlaying) {
  308. self.isPlaying_beforeScroll = YES;
  309. }else {
  310. self.isPlaying_beforeScroll = NO;
  311. }
  312. [self.player pausePlay];
  313. }
  314. - (void)resume {
  315. if (self.isPlaying_beforeScroll) {
  316. [self.player resumePlay];
  317. }
  318. }
  319. - (void)destoryPlayer {
  320. self.scrollView.delegate = nil;
  321. [self.player removeVideo];
  322. [self hiddenGiftView];
  323. }
  324. #pragma mark - Private Methods
  325. - (void)playVideoFrom:(HMVideoControlView *)fromView {
  326. [fromView loadNetDataWithPage:1];
  327. // 移除原来的播放
  328. [self.player removeVideo];
  329. [self.commentView.dataArray removeAllObjects];
  330. [self.commentView.tableView reloadData];
  331. // 取消原来视图的代理
  332. self.currentPlayView.delegate = nil;
  333. // 切换播放视图
  334. self.currentPlayId = fromView.model.video_url;
  335. self.currentPlayView = fromView;
  336. self.currentPlayIndex = [self indexOfModel:fromView.model];
  337. // 设置新视图的代理
  338. self.currentPlayView.delegate = self;
  339. self.commentView.model = self.currentPlayView.model;
  340. // 重新播放
  341. FWWeakify(self)
  342. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  343. FWStrongify(self)
  344. if (fromView.model.video_direction.integerValue == 1) {
  345. //横屏
  346. [self.player.player setRenderMode:RENDER_MODE_FILL_EDGE];
  347. }else{
  348. //竖屏
  349. [self.player.player setRenderMode:RENDER_MODE_FILL_SCREEN];
  350. }
  351. [self.player playVideoWithView:fromView.coverImgView url:fromView.model.video_url];
  352. });
  353. }
  354. // 获取当前播放内容的索引
  355. - (NSInteger)indexOfModel:(SmallVideoListModel *)model {
  356. __block NSInteger index = 0;
  357. [self.videos enumerateObjectsUsingBlock:^(SmallVideoListModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
  358. if ([model.video_url isEqualToString:obj.video_url]) {
  359. index = idx;
  360. }
  361. }];
  362. return index;
  363. }
  364. #pragma mark - UIScrollViewDelegate
  365. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  366. //通知主页面不进行滑动
  367. [[NSNotificationCenter defaultCenter] postNotificationName:@"HMHomeDoNotScroll" object:nil];
  368. if (self.giftView.hidden == NO) {
  369. self.scrollView.scrollEnabled = NO;
  370. return;
  371. }
  372. // 小于等于三个,不用处理
  373. if (self.videos.count <= 3) return;
  374. // 上滑到第一个
  375. if (self.index == 0 && scrollView.contentOffset.y <= kScreenH) {
  376. return;
  377. }
  378. // 下滑到最后一个
  379. if (self.index == self.videos.count - 1 && scrollView.contentOffset.y > kScreenH) {
  380. return;
  381. }
  382. // 判断是从中间视图上滑还是下滑
  383. if (scrollView.contentOffset.y >= 2 * kScreenH) { // 上滑
  384. [self.player removeVideo]; // 在这里移除播放,解决闪动的bug
  385. if (self.index == 0) {
  386. self.index += 2;
  387. scrollView.contentOffset = CGPointMake(0, kScreenH);
  388. self.topView.model = self.middleView.model;
  389. self.middleView.model = self.bottomView.model;
  390. }else {
  391. self.index += 1;
  392. if (self.index == self.videos.count - 1) {
  393. self.middleView.model = self.videos[self.index - 1];
  394. }else {
  395. scrollView.contentOffset = CGPointMake(0, kScreenH);
  396. self.topView.model = self.middleView.model;
  397. self.middleView.model = self.bottomView.model;
  398. }
  399. }
  400. if (self.index < self.videos.count - 1) {
  401. self.bottomView.model = self.videos[self.index + 1];
  402. }
  403. }else if (scrollView.contentOffset.y <= 0) { // 下滑
  404. [self.player removeVideo]; // 在这里移除播放,解决闪动的bug
  405. if (self.index == 1) {
  406. self.topView.model = self.videos[self.index - 1];
  407. self.middleView.model = self.videos[self.index];
  408. self.bottomView.model = self.videos[self.index + 1];
  409. self.index -= 1;
  410. }else {
  411. if (self.index == self.videos.count - 1) {
  412. self.index -= 2;
  413. }else {
  414. self.index -= 1;
  415. }
  416. scrollView.contentOffset = CGPointMake(0, kScreenH);
  417. self.bottomView.model = self.middleView.model;
  418. self.middleView.model = self.topView.model;
  419. if (self.index > 0) {
  420. self.topView.model = self.videos[self.index - 1];
  421. }
  422. }
  423. }
  424. if (self.isPushed) return;
  425. // 自动刷新,如果想要去掉自动刷新功能,去掉下面代码即可
  426. if (scrollView.contentOffset.y == kScreenH) {
  427. if (self.isRefreshMore) return;
  428. // 播放到倒数第二个时,请求更多内容
  429. if (self.currentPlayIndex == self.videos.count - 2) {
  430. self.isRefreshMore = YES;
  431. [self refreshMore];
  432. }
  433. }
  434. if (self.isRefreshMore) return;
  435. if (scrollView.contentOffset.y == 2 * kScreenH) {
  436. [self refreshMore];
  437. }
  438. }
  439. // 结束滚动后开始播放
  440. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  441. if (scrollView.contentOffset.y == 0) {
  442. if ([self.currentPlayId isEqualToString:self.topView.model.video_url]) return;
  443. [self playVideoFrom:self.topView];
  444. self.currentModel = self.topView.model;
  445. }else if (scrollView.contentOffset.y == kScreenH) {
  446. if ([self.currentPlayId isEqualToString:self.middleView.model.video_url]) return;
  447. [self playVideoFrom:self.middleView];
  448. self.currentModel = self.middleView.model;
  449. }else if (scrollView.contentOffset.y == 2 * (kScreenH)) {
  450. if ([self.currentPlayId isEqualToString:self.bottomView.model.video_url]) return;
  451. [self playVideoFrom:self.bottomView];
  452. self.currentModel = self.bottomView.model;
  453. }
  454. }
  455. - (void)refreshMore {
  456. [self.viewModel refreshMoreListWithSuccess:^(NSArray * _Nonnull list) {
  457. self.isRefreshMore = NO;
  458. if (list) {
  459. NSMutableArray *tempArray = [NSMutableArray array];
  460. for (NSDictionary *dict in list)
  461. {
  462. SmallVideoListModel *model = [SmallVideoListModel mj_objectWithKeyValues:dict];
  463. [tempArray addObject:model];
  464. }
  465. [self.videos addObjectsFromArray:tempArray];
  466. if (list.count < 20) {
  467. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  468. }else{
  469. [self.scrollView.mj_footer endRefreshing];
  470. }
  471. }else {
  472. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  473. }
  474. } failure:^(NSError * _Nonnull error) {
  475. NSLog(@"%@", error);
  476. self.isRefreshMore = NO;
  477. [self.scrollView.mj_footer endRefreshingWithNoMoreData];
  478. } WithRequestDict:self.dict];
  479. }
  480. #pragma mark - HMVideoPlayerDelegate
  481. - (void)player:(HMVideoPlayer *)player statusChanged:(HMVideoPlayerStatus)status {
  482. switch (status) {
  483. case HMVideoPlayerStatusUnload: // 未加载
  484. break;
  485. case HMVideoPlayerStatusPrepared: // 准备播放
  486. break;
  487. case HMVideoPlayerStatusLoading: { // 加载中
  488. [self.currentPlayView startLoading];
  489. [self.currentPlayView hidePlayBtn];
  490. }
  491. break;
  492. case HMVideoPlayerStatusPlaying: { // 播放中
  493. [self.currentPlayView stopLoading];
  494. [self.currentPlayView hidePlayBtn];
  495. }
  496. break;
  497. case HMVideoPlayerStatusPaused: { // 暂停
  498. [self.currentPlayView stopLoading];
  499. [self.currentPlayView showPlayBtn];
  500. }
  501. break;
  502. case HMVideoPlayerStatusEnded: { // 播放结束
  503. // 重新开始播放
  504. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  505. HMVideoPlayerViewController *newVC = (HMVideoPlayerViewController *)self.vc;
  506. if (newVC.isViewAppear) {
  507. [self.player resetPlay];
  508. }else{
  509. [self.player pausePlay];
  510. }
  511. });
  512. }
  513. break;
  514. case HMVideoPlayerStatusError: // 错误
  515. break;
  516. default:
  517. break;
  518. }
  519. }
  520. #pragma mark - HMVideoPlayerDelegate
  521. - (void)player:(HMVideoPlayer *)player currentTime:(float)currentTime totalTime:(float)totalTime progress:(float)progress {
  522. dispatch_async(dispatch_get_main_queue(), ^{
  523. [self.currentPlayView setProgress:progress];
  524. });
  525. }
  526. #pragma mark - HMVideoControlViewDelegate
  527. - (void)controlViewDidClickSelf:(HMVideoControlView *)controlView {
  528. self.scrollView.scrollEnabled = YES;
  529. if (self.giftView.hidden) {
  530. if (self.player.isPlaying) {
  531. [self.player pausePlay];
  532. }else {
  533. [self.player resumePlay];
  534. }
  535. return;
  536. }
  537. if (self.delegate && [self.delegate respondsToSelector:@selector(controlViewDidClickSelf:)]) {
  538. [self.delegate controlViewDidClickSelf:self];
  539. }
  540. // if (!self.giftView.hidden) {
  541. // [self hiddenGiftView];
  542. // return;
  543. // }
  544. }
  545. - (void)controlViewDidClickIcon:(HMVideoControlView *)controlView {
  546. if (![IMAPlatform isAutoLogin]) {
  547. [[AppDelegate sharedAppDelegate] enterLoginUI];
  548. return;
  549. }
  550. NSString *userId = controlView.model.user_id;
  551. if (self.clickHeadBlock) {
  552. self.clickHeadBlock(userId);
  553. }
  554. }
  555. -(void)controlViewDidClickMoreBtn:(HMVideoControlView *)controlView{
  556. if (![IMAPlatform isAutoLogin]) {
  557. [[AppDelegate sharedAppDelegate] enterLoginUI];
  558. return;
  559. }
  560. if (![controlView.model.user_id isEqualToString:[BGIMLoginManager sharedInstance].loginParam.identifier]){
  561. if (self.delegate && [self.delegate respondsToSelector:@selector(videoViewDidClickReport:)]) {
  562. [self.delegate videoViewDidClickReport:self];
  563. }
  564. }else{
  565. [self deleteTap];
  566. }
  567. // LCActionSheet *sheet = [LCActionSheet sheetWithTitle:ASLocalizedString(@"选择")cancelButtonTitle:ASLocalizedString(@"取消")clicked:^(LCActionSheet * _Nonnull actionSheet, NSInteger buttonIndex) {
  568. // if (buttonIndex == 1) {
  569. // [self deleteTap];
  570. // }
  571. // } otherButtonTitles:ASLocalizedString(@"删除动态"), nil];
  572. //
  573. // [sheet show];
  574. }
  575. - (void)deleteTap{
  576. [FanweMessage alert:ASLocalizedString(@"提示")message:ASLocalizedString(@"是否删除此条视频")destructiveAction:^{
  577. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  578. [dict setValue:@"del_weibo" forKey:@"act"];
  579. [dict setValue:@"publish" forKey:@"ctl"];
  580. NSString *weibo_id = @"";
  581. if ([self.currentModel isKindOfClass:[NSDictionary class]]) {
  582. NSDictionary *nDic = (NSDictionary *)self.currentModel;
  583. weibo_id = nDic[@"weibo_id"];
  584. }else{
  585. weibo_id = self.currentModel.weibo_id;
  586. }
  587. [dict setValue:weibo_id forKey:@"weibo_id"];
  588. [dict setValue:@"xr" forKey:@"itype"];
  589. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  590. if ([responseJson toInt:@"status"] == 1) {
  591. [FanweMessage alertHUD:[responseJson valueForKeyPath:@"error"]];
  592. // [FanweMessage alert:ASLocalizedString(@"提示")message:[responseJson valueForKeyPath:@"error"] isHideTitle:NO destructiveAction:^{
  593. if (self.delegate && [self.delegate respondsToSelector:@selector(deleteVideoWithView:)]) {
  594. [self.delegate deleteVideoWithView:self];
  595. }
  596. // }];
  597. }else{
  598. }
  599. } FailureBlock:^(NSError *error) {
  600. [FanweMessage alert:ASLocalizedString(@"删除失败")];
  601. }];
  602. } cancelAction:^{
  603. }];
  604. }
  605. - (void)controlViewDidClickPriase:(HMVideoControlView *)controlView {
  606. if (![IMAPlatform isAutoLogin]) {
  607. [[AppDelegate sharedAppDelegate] enterLoginUI];
  608. return;
  609. }
  610. //点击点赞按钮
  611. NSMutableDictionary *MDict = [NSMutableDictionary new];
  612. [MDict setObject:@"user" forKey:@"ctl"];
  613. [MDict setObject:@"publish_comment" forKey:@"act"];
  614. if (controlView.model.weibo_id.length)
  615. {
  616. [MDict setObject:controlView.model.weibo_id forKey:@"weibo_id"];
  617. }
  618. [MDict setObject:@"xr" forKey:@"itype"];
  619. [MDict setObject:@"2" forKey:@"type"];
  620. [MDict setObject:controlView.model.user_id forKey:@"user_id"];
  621. [self.httpsManager POSTWithParameters:MDict SuccessBlock:^(NSDictionary *responseJson)
  622. {
  623. if ([responseJson toInt:@"status"]== 1)
  624. {
  625. NSString *digg_count = [responseJson toString:@"digg_count"];
  626. int has_digg = [responseJson toInt:@"has_digg"];
  627. NSMutableDictionary *postDict = [[NSMutableDictionary alloc]init];
  628. [postDict setObject:@"dianZan" forKey:@"type"];
  629. [postDict setObject:[NSString stringWithFormat:@"%@",digg_count] forKey:@"count"];
  630. [postDict setObject:[NSString stringWithFormat:@"%d",has_digg] forKey:@"has_digg"];
  631. // [postDict setObject:[NSString stringWithFormat:@"%d",self.lastView] forKey:@"reloadView"];
  632. // [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:postDict];
  633. [controlView setiIsPraise:has_digg diggcount:digg_count];
  634. }
  635. // NSIndexPath *te = [NSIndexPath indexPathForRow:0 inSection:FWPCDetailOneSection];//刷新某段某行
  636. [[BGHUDHelper sharedInstance] tipMessage:[responseJson toString:@"error"]];
  637. } FailureBlock:^(NSError *error)
  638. {
  639. NSLog(@"error==%@",error);
  640. }];
  641. }
  642. - (void)controlViewDidClickComment:(HMVideoControlView *)controlView DataArray:(NSMutableArray *)dataArray {
  643. if (![IMAPlatform isAutoLogin]) {
  644. [[AppDelegate sharedAppDelegate] enterLoginUI];
  645. return;
  646. }
  647. //点击评论按钮
  648. [self.commentView show:[UIApplication sharedApplication].keyWindow];
  649. }
  650. - (void)controlViewDidClickShare:(HMVideoControlView *)controlView ShareDict:(NSMutableDictionary *)shareDict {
  651. if (![IMAPlatform isAutoLogin]) {
  652. [[AppDelegate sharedAppDelegate] enterLoginUI];
  653. return;
  654. }
  655. // 点击分享
  656. _shareDict = shareDict;
  657. [self.shareView show:[UIApplication sharedApplication].keyWindow isNeedReport:![controlView.model.user_id isEqualToString:[[IMAPlatform sharedInstance].host imUserId]]];
  658. }
  659. -(void)controlViewDidClickGift:(HMVideoControlView *)controlView{
  660. if (![IMAPlatform isAutoLogin]) {
  661. [[AppDelegate sharedAppDelegate] enterLoginUI];
  662. return;
  663. }
  664. self.currentModel = controlView.model;
  665. self.giftView.hidden = NO;
  666. // self.giftView.topView.hidden = YES;
  667. __weak __typeof(self)weakSelf = self;
  668. [UIView animateWithDuration:0.1 animations:^{
  669. weakSelf.giftView.frame = CGRectMake(0, kScreenH-_giftViewHeight - (IPHONE_X ? 34 : 0) - (self.isPushed ? 0 : 0), _giftView.frame.size.width, _giftView.frame.size.height);
  670. [[[UIApplication sharedApplication].delegate window].rootViewController.view bringSubviewToFront:_giftView];
  671. }completion:^(BOOL finished) {
  672. }];
  673. }
  674. #pragma mark 点击发送礼物
  675. - (void)senGift:(GiftView *)giftView AndGiftModel:(GiftModel *)giftModel
  676. {
  677. _currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  678. if (_currentDiamonds < giftModel.diamonds)
  679. {
  680. _giftView.sendBtn.hidden = NO;
  681. _giftView.continueContainerView.hidden = YES;
  682. [self showRechargeAlert:ASLocalizedString(@"当前余额不足,充值才能继续送礼,是否去充值?")];
  683. return;
  684. }
  685. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  686. [mDict setObject:@"svideo" forKey:@"ctl"];
  687. [mDict setObject:@"send_gift" forKey:@"act"];
  688. [mDict setObject:self.currentModel.user_id forKey:@"to_uid"];
  689. [mDict setObject:self.currentModel.weibo_id forKey:@"w_id"];
  690. [mDict setObject:@"1" forKey:@"num"];
  691. // [NSString stringWithFormat:@"%ld",giftModel.diamonds]
  692. [mDict setObject:@"" forKey:@"price_type"];
  693. [mDict setObject:[NSString stringWithFormat:@"%ld",giftModel.ID] forKey:@"g_id"];
  694. FWWeakify(self)
  695. [self.httpsManager POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  696. FWStrongify(self)
  697. if ([responseJson toInt:@"status"] == 1)
  698. {
  699. self.currentDiamonds -= giftModel.diamonds;
  700. if (self.currentDiamonds >= 0)
  701. {
  702. [self.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  703. // [[IMAPlatform sharedInstance].host setDiamonds:[NSString stringWithFormat:@"%ld",(long)self.currentDiamonds]];
  704. }
  705. GiftModel *newModel = [GiftModel mj_objectWithKeyValues:responseJson[@"data"]];
  706. [self showSendGiftSuccessWithModel:newModel];
  707. [self changeMoney];
  708. }
  709. } FailureBlock:^(NSError *error) {
  710. }];
  711. }
  712. - (void)showSendGiftSuccessWithModel:(GiftModel *)giftModel
  713. {
  714. // if (giftModel.is_much == 0)
  715. // {
  716. // [FanweMessage alertHUD:ASLocalizedString(@"发送成功")];
  717. // [FanweMessage alert:[NSString stringWithFormat:ASLocalizedString(@"%@ 已发送"),giftModel.name]];
  718. // }
  719. [self.animationArray addObject:giftModel];
  720. [self.tipAnimationArray addObject:giftModel];
  721. if (!self.isAnimated) {
  722. [self startTipGiftAnimation];
  723. self.isAnimated = YES;
  724. }
  725. if (giftModel.is_animated == 2) {
  726. if (!self.isBigAnimated) {
  727. GiftModel *model = self.animationArray.lastObject;
  728. [self.animationView setGiftModel:model];
  729. self.isBigAnimated = YES;
  730. }
  731. }else if (giftModel.is_animated == 1){
  732. if (!self.isBigAnimated) {
  733. for (AnimateConfigModel *configModel in giftModel.anim_cfg) {
  734. GifImageView *gifImageView = [[GifImageView alloc]initWithModel:configModel inView:self andSenderName:[IMAPlatform sharedInstance].host.imUserName];
  735. gifImageView.delegate = self;
  736. }
  737. self.isBigAnimated = YES;
  738. }
  739. }
  740. }
  741. - (void)showRechargeAlert:(NSString *)message
  742. {
  743. FWWeakify(self)
  744. [FanweMessage alert:ASLocalizedString(@"余额不足")message:message destructiveAction:^{
  745. // FWStrongify(self)
  746. // if (_liveInputView.barrageBtn.isSelected &&!_liveInputView.isHost)
  747. // { // 打开了 弹幕
  748. [self showRechargeView:_giftView];
  749. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  750. //
  751. // [self.liveInputView.textField resignFirstResponder];
  752. //
  753. // });
  754. // }
  755. // else
  756. // {
  757. // [self showRechargeView:_giftView];
  758. // }
  759. } cancelAction:^{
  760. // if (_liveInputView.barrageBtn.isSelected && !_liveInputView.isHost)
  761. // {// 打开了 弹幕
  762. // _liveInputView.hidden = NO;
  763. // _bottomView.hidden = YES;
  764. // [_liveInputView becomeFirstResponder];
  765. // }
  766. }];
  767. }
  768. - (void)showRechargeView:(GiftView *)giftView{
  769. if (self.delegate && [self.delegate respondsToSelector:@selector(videoViewDidClickRecharge:)]) {
  770. [self.delegate videoViewDidClickRecharge:self];
  771. }
  772. }
  773. - (void)controlViewDidClickBottomComment:(HMVideoControlView *)controlView{
  774. [self.currentPlayView commentBtnClick:self.currentPlayView.commentBtn];
  775. }
  776. - (void)controlViewDidClickFocus:(HMVideoControlView *)controlView{
  777. //点击了关注按钮
  778. }
  779. - (void)controlViewDidClickOneOnOne:(HMVideoControlView *)controlView{
  780. [self.player pausePlay];
  781. if (self.delegate && [self.delegate respondsToSelector:@selector(videoViewDidClickOneOnOne:)]) {
  782. [self.delegate videoViewDidClickOneOnOne:self];
  783. }
  784. }
  785. #pragma mark - HMShareViewDelegate
  786. - (void)clickShareViewBtn:(UMSocialPlatformType)type{
  787. if (![[UMSocialManager defaultManager] isSupport:type]){
  788. switch (type) {
  789. case UMSocialPlatformType_Sina:
  790. [FanweMessage alert:ASLocalizedString(@"新浪微博未安装")];
  791. break;
  792. case UMSocialPlatformType_WechatSession:
  793. [FanweMessage alert:ASLocalizedString(@"微信未安装")];
  794. break;
  795. case UMSocialPlatformType_WechatTimeLine:
  796. [FanweMessage alert:ASLocalizedString(@"微信未安装")];
  797. break;
  798. case UMSocialPlatformType_QQ:
  799. [FanweMessage alert:ASLocalizedString(@"QQ未安装")];
  800. break;
  801. case UMSocialPlatformType_Qzone:
  802. [FanweMessage alert:ASLocalizedString(@"QQ未安装")];
  803. break;
  804. default:
  805. break;
  806. }
  807. return;
  808. }
  809. ShareModel *model = [[ShareModel alloc]init];
  810. model.share_content = _shareDict[@"share_content"];
  811. model.share_title = _shareDict[@"share_title"];
  812. model.share_url = _shareDict[@"share_url"];
  813. model.share_imageUrl = _shareDict[@"share_imageUrl"];
  814. //创建分享消息对象
  815. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  816. //创建网页内容对象
  817. NSString* thumbURL = _shareDict[@"share_imageUrl"];
  818. UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:_shareDict[@"share_title"] descr:_shareDict[@"share_content"] thumImage:thumbURL];
  819. //设置网页地址
  820. shareObject.webpageUrl = _shareDict[@"share_url"];
  821. //分享消息对象设置分享内容对象
  822. messageObject.shareObject = shareObject;
  823. //调用分享接口
  824. [[UMSocialManager defaultManager] shareToPlatform:type messageObject:messageObject currentViewController:[self viewController] completion:^(id data, NSError *error) {
  825. if (error) {
  826. UMSocialLogInfo(@"************Share fail with error %@*********",error);
  827. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:@"%@",error.userInfo[@"share error"]]];
  828. }else{
  829. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"分享成功")];
  830. // if ([data isKindOfClass:[UMSocialShareResponse class]]) {
  831. // UMSocialShareResponse *resp = data;
  832. // //分享结果消息
  833. // UMSocialLogInfo(@"response message is %@",resp.message);
  834. // [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"分享失败: %@"),resp.message]];
  835. // //第三方原始返回的数据
  836. // UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
  837. // }else{
  838. // UMSocialLogInfo(@"response data is %@",data);
  839. // [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:ASLocalizedString(@"分享失败: %@"),data]];
  840. // }
  841. }
  842. }];
  843. }
  844. - (void)clickShareViewReportBtn{
  845. [self.player pausePlay];
  846. BGReportController *reportVC = [[BGReportController alloc]init];
  847. reportVC.weibo_id = self.currentPlayView.model.weibo_id;
  848. reportVC.to_user_id = self.currentPlayView.model.user_id;
  849. reportVC.reportType = 1;
  850. [[AppDelegate sharedAppDelegate] pushViewController:reportVC animated:YES];
  851. }
  852. #pragma mark 创建礼物视图及礼物动画视图
  853. - (void)loadGiftView:(NSArray *)list
  854. {
  855. NSMutableArray *giftMArray = [NSMutableArray array];
  856. if (list && [list isKindOfClass:[NSArray class]])
  857. {
  858. for (NSDictionary *key in list)
  859. {
  860. GiftModel *giftModel = [GiftModel mj_objectWithKeyValues:key];
  861. [giftMArray addObject:giftModel];
  862. }
  863. }
  864. BOOL ret = NO;
  865. for (GiftModel *giftModel in giftMArray) {
  866. if (giftModel.list.count > 4) {
  867. ret = YES;
  868. break;
  869. }
  870. }
  871. // if (ret) {
  872. // _giftViewHeight = kRealValue(358) + MG_BOTTOM_MARGIN;
  873. // kScreenW*0.56+kSendGiftContrainerHeight+4*kDefaultMargin + MG_BOTTOM_MARGIN;
  874. // }else{
  875. // _giftViewHeight = kScreenW*0.28+kSendGiftContrainerHeight+4*kDefaultMargin;
  876. // }
  877. _giftViewHeight = KGiftViewHeight;
  878. // 礼物视图
  879. _giftView = [[GiftView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, _giftViewHeight)];
  880. _giftView.delegate = self;
  881. _giftView.hidden = YES;
  882. [_giftView setGiftView:giftMArray];
  883. // [self.superview.superview.superview.superview addSubview:_giftView];
  884. [[[UIApplication sharedApplication].delegate window].rootViewController.view addSubview:_giftView];
  885. NSLog(@"_giftView_giftView%@",[[UIApplication sharedApplication].delegate window].rootViewController);
  886. // [[UIApplication sharedApplication].keyWindow addSubview:_giftView];
  887. [self changeMoney];
  888. }
  889. #pragma mark 钻石值的改变,刷新用户信息
  890. - (void)changeMoney
  891. {
  892. FWWeakify(self)
  893. [[IMAPlatform sharedInstance].host getMyInfo:^(AppBlockModel *blockModel) {
  894. FWStrongify(self)
  895. NSInteger currentDiamonds = [[IMAPlatform sharedInstance].host getDiamonds];
  896. [self.giftView setDiamondsLabelTxt:[NSString stringWithFormat:@"%ld",(long)currentDiamonds]];
  897. }];
  898. }
  899. #pragma mark 隐藏giftView
  900. - (void)hiddenGiftView
  901. {
  902. FWWeakify(self)
  903. [UIView animateWithDuration:0.1 animations:^{
  904. FWStrongify(self)
  905. self.giftView.frame = CGRectMake(0, self.frame.size.height, _giftView.frame.size.width, _giftView.frame.size.height);
  906. }completion:^(BOOL finished) {
  907. FWStrongify(self)
  908. self.giftView.hidden = YES;
  909. }];
  910. }
  911. - (UIViewController *)viewController{
  912. for (UIView *next = [self superview]; next; next = next.superview) {
  913. UIResponder *nextResponser = [next nextResponder];
  914. if ([nextResponser isKindOfClass:[UITableViewController class]]) {
  915. return (UIViewController *)nextResponser;
  916. }
  917. }
  918. return nil;
  919. }
  920. #pragma mark -------------- Lazy Load -------------------
  921. - (HMVideoViewModel *)viewModel {
  922. if (!_viewModel) {
  923. _viewModel = [HMVideoViewModel new];
  924. _viewModel.isPushed = self.isPushed;
  925. }
  926. return _viewModel;
  927. }
  928. - (UIScrollView *)scrollView {
  929. if (!_scrollView) {
  930. _scrollView = [UIScrollView new];
  931. _scrollView.pagingEnabled = YES;
  932. _scrollView.backgroundColor = kBlackColor;
  933. _scrollView.showsVerticalScrollIndicator = NO;
  934. _scrollView.showsHorizontalScrollIndicator = NO;
  935. _scrollView.delegate = self;
  936. [_scrollView addSubview:self.topView];
  937. [_scrollView addSubview:self.middleView];
  938. [_scrollView addSubview:self.bottomView];
  939. _scrollView.contentSize = CGSizeMake(0, kScreenH * 3);
  940. if (@available(iOS 11.0, *)) {
  941. _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  942. } else {
  943. // Fallback on earlier versions
  944. }
  945. }
  946. return _scrollView;
  947. }
  948. - (HMVideoControlView *)topView {
  949. if (!_topView) {
  950. _topView = [[HMVideoControlView alloc] initWithIsPushed:self.isPushed];
  951. }
  952. return _topView;
  953. }
  954. - (HMVideoControlView *)middleView {
  955. if (!_middleView) {
  956. _middleView = [[HMVideoControlView alloc] initWithIsPushed:self.isPushed];
  957. }
  958. return _middleView;
  959. }
  960. - (HMVideoControlView *)bottomView {
  961. if (!_bottomView) {
  962. _bottomView = [[HMVideoControlView alloc] initWithIsPushed:self.isPushed];
  963. }
  964. return _bottomView;
  965. }
  966. - (NSMutableArray *)videos {
  967. if (!_videos) {
  968. _videos = [NSMutableArray new];
  969. }
  970. return _videos;
  971. }
  972. - (HMVideoPlayer *)player {
  973. if (!_player) {
  974. _player = [HMVideoPlayer new];
  975. _player.delegate = self;
  976. }
  977. return _player;
  978. }
  979. - (HMCommentView *)commentView{
  980. if (!_commentView) {
  981. _commentView = [[HMCommentView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH)];
  982. FWWeakify(self)
  983. [_commentView setOperateCommentSuccessBlock:^(NSString * _Nonnull commentCount) {
  984. FWStrongify(self)
  985. [self.currentPlayView.commentBtn setTitle:commentCount forState:UIControlStateNormal];
  986. }];
  987. }
  988. return _commentView;
  989. }
  990. - (HMShareView *)shareView{
  991. if (!_shareView) {
  992. _shareView = [[HMShareView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH)];
  993. _shareView.delegate = self;
  994. }
  995. return _shareView;
  996. }
  997. - (void)startGiftAnimation{
  998. GiftModel *model = self.animationArray.lastObject;
  999. if (self.animationArray.count) {
  1000. if (model.is_animated == 2) {
  1001. [self.animationView setGiftModel:model];
  1002. }else if (model.is_animated == 1){
  1003. for (AnimateConfigModel *configModel in model.anim_cfg) {
  1004. GifImageView *gifImageView = [[GifImageView alloc]initWithModel:configModel inView:self andSenderName:[IMAPlatform sharedInstance].host.imUserName];
  1005. gifImageView.delegate = self;
  1006. }
  1007. }
  1008. }
  1009. }
  1010. - (void)startTipGiftAnimation{
  1011. if (self.tipAnimationArray.count) {
  1012. GiftModel *model = self.tipAnimationArray.lastObject;
  1013. [self addSubview:self.tipAnimationView];
  1014. [self.tipAnimationView setGiftModel:model];
  1015. }
  1016. }
  1017. #pragma mark - SVGAAnimationViewDelegate
  1018. - (void)svgaAnimationView:(SVGAAnimationView *)svgaAnimationView didFinishAnimation:(GiftModel *)msgModel{
  1019. [self.animationArray removeObject:msgModel];
  1020. self.isBigAnimated = self.animationArray.count;
  1021. [self startGiftAnimation];
  1022. }
  1023. #pragma mark - BGVideoGiftAnimationViewDelegate
  1024. - (void)animationView:(BGVideoGiftAnimationView *)animationView didFinishAnimation:(GiftModel *)model{
  1025. self.isAnimated = NO;
  1026. [animationView removeFromSuperview];
  1027. [self.tipAnimationArray removeLastObject];
  1028. [self startTipGiftAnimation];
  1029. }
  1030. #pragma mark GifImageViewDelegate
  1031. - (void)gifImageViewFinish:(AnimateConfigModel *)animateConfigModel andSenderName:(NSString *)senderName{
  1032. [self.animationArray removeLastObject];
  1033. self.isBigAnimated = self.animationArray.count;
  1034. [self startGiftAnimation];
  1035. }
  1036. - (NSMutableArray *)animationArray{
  1037. if (!_animationArray) {
  1038. _animationArray = [NSMutableArray array];
  1039. }
  1040. return _animationArray;
  1041. }
  1042. - (SVGAAnimationView *)animationView{
  1043. if (!_animationView) {
  1044. _animationView = [[SVGAAnimationView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  1045. _animationView.delegate = self;
  1046. }
  1047. return _animationView;
  1048. }
  1049. - (NSMutableArray *)tipAnimationArray{
  1050. if (!_tipAnimationArray) {
  1051. _tipAnimationArray = [NSMutableArray array];
  1052. }
  1053. return _tipAnimationArray;
  1054. }
  1055. - (BGVideoGiftAnimationView *)tipAnimationView{
  1056. if (!_tipAnimationView) {
  1057. _tipAnimationView = [[NSBundle mainBundle] loadNibNamed:@"BGVideoGiftAnimationView" owner:nil options:nil].lastObject;
  1058. _tipAnimationView.delegate = self;
  1059. }
  1060. return _tipAnimationView;
  1061. }
  1062. //- (NSMutableArray *)gifImageViewArray{
  1063. // if (!_gifImageViewArray) {
  1064. // _gifImageViewArray = [NSMutableArray array];
  1065. // }
  1066. // return _gifImageViewArray;
  1067. //}
  1068. - (void)mineBtnAction:(UIButton *)sender{
  1069. if ([IMAPlatform isAutoLogin]) {
  1070. MPersonCenterVC *vc = [[MPersonCenterVC alloc]init];
  1071. [[AppDelegate sharedAppDelegate] pushViewController:vc animated:YES];
  1072. }else{
  1073. [[AppDelegate sharedAppDelegate] enterLoginUI];
  1074. }
  1075. }
  1076. - (void)searchBtnAction:(UIButton *)sender{
  1077. if ([IMAPlatform isAutoLogin]) {
  1078. SSearchVC *searchVC = [[SSearchVC alloc]init];
  1079. searchVC.searchType = @"0";
  1080. }else{
  1081. [[AppDelegate sharedAppDelegate] enterLoginUI];
  1082. }
  1083. }
  1084. - (UIButton *)mineBtn{
  1085. if (!_mineBtn) {
  1086. _mineBtn = [[UIButton alloc]initWithFrame:CGRectMake(15, 15 + kStatusBarHeight, 44, 44)];
  1087. [_mineBtn setImage:[UIImage imageNamed:@"hm_new_admin"] forState:UIControlStateNormal];
  1088. [_mineBtn addTarget:self action:@selector(mineBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  1089. }
  1090. return _mineBtn;
  1091. }
  1092. - (UIButton *)searchBtn{
  1093. if (!_searchBtn) {
  1094. _searchBtn = [[UIButton alloc]initWithFrame:CGRectMake(kScreenW - 15 - 44, 15 + kStatusBarHeight, 44, 44)];
  1095. [_searchBtn setImage:[UIImage imageNamed:@"hm_new_search"] forState:UIControlStateNormal];
  1096. [_searchBtn addTarget:self action:@selector(searchBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  1097. }
  1098. return _searchBtn;
  1099. }
  1100. - (void)dealloc{
  1101. [self hiddenGiftView];
  1102. }
  1103. @end