HMVideoView.m 47 KB

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