JXDetailViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. //
  2. // JXDetailViewController.m
  3. // AICity
  4. //
  5. // Created by TogetherWatch on 2025-10-13.
  6. // 短剧详情+播放器页面(对标Android的JuXingPlayerActivity)
  7. //
  8. #import "JXDetailViewController.h"
  9. #import "JXAPIService.h"
  10. #import "JXCacheManager.h"
  11. #import "JXDrama.h"
  12. #import "JXEpisode.h"
  13. #import "JXInteraction.h"
  14. #import "JXAVPlayer.h"
  15. #import "JXSuperPlayer.h"
  16. #import <AVFoundation/AVFoundation.h>
  17. #import "JXCollectionViewController.h"
  18. #import "JXCommentViewController.h"
  19. #import <TXLiteAVSDK_Player/TXLiteAVSDK.h>
  20. #import "VideoDetailCell.h"
  21. @interface JXDetailViewController () <JXSuperPlayerDelegate, UICollectionViewDelegate, UICollectionViewDataSource,JXCollectionViewControllerDelegate,VideoDetailCellDelegate>{
  22. JXSuperPlayer *_currentPlayer;
  23. }
  24. // 播放器
  25. @property (nonatomic, strong) UIView *playerContainer;
  26. @property (nonatomic, strong) JXSuperPlayer *player;
  27. // UI组件
  28. @property (nonatomic, strong) UICollectionView *episodeCollectionView;
  29. @property (nonatomic, strong) UILabel *titleLabel;
  30. @property (nonatomic, strong) UILabel *descLabel;
  31. @property (nonatomic, strong) UILabel *authorLabel;
  32. @property (nonatomic, strong) UIButton *likeButton;
  33. @property (nonatomic, strong) UILabel *likeCountLabel;
  34. @property (nonatomic, strong) UIButton *favoriteButton;
  35. @property (nonatomic, strong) UILabel *favoriteCountLabel;
  36. @property (nonatomic, strong) UIButton *commentButton;
  37. @property (nonatomic, strong) UILabel *commentCountLabel;
  38. // 数据
  39. @property (nonatomic, strong) JXDrama *drama;
  40. @property (nonatomic, strong) NSArray<JXEpisode *> *episodes;
  41. @property (nonatomic, strong) JXInteraction *interaction;
  42. @property (nonatomic, assign) NSInteger currentEpisodeIndex;
  43. @property (strong, nonatomic) UISlider *videoSlider;
  44. @property (nonatomic,assign) BOOL isHuadong;
  45. @property (strong, nonatomic) NSMutableArray *playerList;
  46. @property (strong, nonatomic) JXInteraction *pageData;
  47. @end
  48. @implementation JXDetailViewController
  49. - (instancetype)initWithDramaId:(NSString *)dramaId {
  50. self = [super init];
  51. if (self) {
  52. _dramaId = [dramaId copy];
  53. _currentEpisodeIndex = 0;
  54. }
  55. return self;
  56. }
  57. - (void)viewDidLoad {
  58. [super viewDidLoad];
  59. self.view.backgroundColor = [UIColor blackColor];
  60. // 隐藏导航栏返回按钮
  61. self.navigationItem.hidesBackButton = YES;
  62. [self setupUI];
  63. [self loadData];
  64. }
  65. - (void)setupUI {
  66. CGFloat width = self.view.bounds.size.width;
  67. CGFloat height = self.view.bounds.size.height;
  68. // 创建垂直滚动的CollectionView(每集占满屏幕)
  69. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  70. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  71. layout.itemSize = CGSizeMake(width, height);
  72. layout.minimumLineSpacing = 0;
  73. layout.minimumInteritemSpacing = 0;
  74. self.episodeCollectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds
  75. collectionViewLayout:layout];
  76. self.episodeCollectionView.backgroundColor = [UIColor blackColor];
  77. self.episodeCollectionView.delegate = self;
  78. self.episodeCollectionView.dataSource = self;
  79. self.episodeCollectionView.pagingEnabled = YES;
  80. self.episodeCollectionView.showsVerticalScrollIndicator = NO;
  81. [self.episodeCollectionView registerClass:[UICollectionViewCell class]
  82. forCellWithReuseIdentifier:@"EpisodeCell"];
  83. [self.episodeCollectionView registerClass:[VideoDetailCell class] forCellWithReuseIdentifier:NSStringFromClass(VideoDetailCell.class)];
  84. [self.view addSubview:self.episodeCollectionView];
  85. // 设置约束
  86. self.episodeCollectionView.translatesAutoresizingMaskIntoConstraints = NO;
  87. [NSLayoutConstraint activateConstraints:@[
  88. [self.episodeCollectionView.topAnchor constraintEqualToAnchor:self.view.topAnchor],
  89. [self.episodeCollectionView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
  90. [self.episodeCollectionView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
  91. [self.episodeCollectionView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor]
  92. ]];
  93. }
  94. - (void)loadData {
  95. if (!self.dramaId) {
  96. return;
  97. }
  98. // 从网络加载
  99. [[JXAPIService sharedService] getDramaDetailWithDramaId:self.dramaId success:^(id responseObject) {
  100. NSDictionary *response = responseObject;
  101. NSLog(@"📡 getDramaDetail响应代码: %@", response[@"code"]);
  102. NSLog(@"📡 getDramaDetail完整响应: %@", response);
  103. if ([response[@"code"] intValue] == 0) {
  104. NSDictionary *data = response[@"data"];
  105. NSLog(@"✅ 获取短剧数据成功");
  106. NSLog(@"📊 Drama数据: %@", data[@"drama"]);
  107. NSLog(@"📊 Episodes数量: %lu", (unsigned long)[data[@"episodes"] count]);
  108. [self updateUIWithData:data];
  109. // 自动滚动到第一集
  110. NSLog(@"⏯️ 自动滚动检查 - 剧集总数: %lu", (unsigned long)self.episodes.count);
  111. if (self.episodes.count > 0) {
  112. NSLog(@"⏯️ 滚动到第一集");
  113. [self.episodeCollectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:self.playIndex inSection:0]
  114. atScrollPosition:UICollectionViewScrollPositionCenteredVertically
  115. animated:NO];
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. [self playVideoAtIndex:0];
  118. });
  119. } else {
  120. NSLog(@"❌ 剧集列表为空,无法播放");
  121. }
  122. } else {
  123. NSLog(@"❌ API返回错误代码: %@", response[@"code"]);
  124. }
  125. } failure:^(NSError *error) {
  126. NSLog(@"❌ 加载短剧详情失败: %@", error.localizedDescription);
  127. }];
  128. }
  129. - (void)updateUIWithData:(NSDictionary *)data {
  130. // 解析数据
  131. self.drama = [[JXDrama alloc] initWithDictionary:data[@"drama"]];
  132. NSArray *episodesData = data[@"episodes"];
  133. NSMutableArray *episodesList = [NSMutableArray array];
  134. for (NSDictionary *episodeDict in episodesData) {
  135. JXEpisode *episode = [[JXEpisode alloc] initWithDictionary:episodeDict];
  136. [episodesList addObject:episode];
  137. }
  138. self.episodes = episodesList;
  139. self.interaction = [[JXInteraction alloc] initWithDictionary:data[@"interaction"]];
  140. [self.episodeCollectionView reloadData];
  141. }
  142. #pragma mark - UICollectionViewDataSource
  143. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  144. return self.episodes.count;
  145. }
  146. //- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  147. // UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EpisodeCell"
  148. // forIndexPath:indexPath];
  149. //
  150. // // 清理之前的子视图
  151. // for (UIView *view in cell.contentView.subviews) {
  152. // [view removeFromSuperview];
  153. // }
  154. //
  155. // cell.contentView.backgroundColor = [UIColor redColor];
  156. //
  157. // CGFloat width = cell.contentView.bounds.size.width;
  158. // CGFloat height = cell.contentView.bounds.size.height;
  159. //
  160. // // 播放器容器(占据上半部分)
  161. // CGFloat playerHeight = height;
  162. // UIView *playerContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, playerHeight)];
  163. // playerContainer.backgroundColor = [UIColor blackColor];
  164. // [cell.contentView addSubview:playerContainer];
  165. // [cell.contentView sendSubviewToBack:playerContainer];
  166. // // 创建播放器
  167. // JXSuperPlayer *player = [[JXSuperPlayer alloc] initWithContainerView:playerContainer];
  168. // player.delegate = self;
  169. // // 右侧互动按钮
  170. // [self setupInteractionButtonsForCell:cell];
  171. //
  172. // UILabel * seeL = [[UILabel alloc] initWithFrame:CGRectMake(16, kScreenHeight - 14-safebottom, SCREEN_WIDTH - 32, 14)];
  173. // seeL.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
  174. // seeL.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1];
  175. // [cell.contentView addSubview:seeL];
  176. // seeL.text = [NSString stringWithFormat:@"%@次播放",@"30万"];
  177. //
  178. // UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMinY(seeL.frame) - 58, SCREEN_WIDTH, 38)];
  179. // bottomView.backgroundColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.1];
  180. // [cell.contentView addSubview:bottomView];
  181. // UIImageView *sImgView = [[UIImageView alloc] initWithFrame:CGRectMake(16, 10.5, 17, 17)];
  182. // sImgView.image = [UIImage imageNamed:@"icon 2.1 拷贝"];
  183. // [bottomView addSubview:sImgView];
  184. // UILabel *hjL = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(sImgView.frame)+4, 0, 100, 38)];
  185. // [bottomView addSubview:hjL];
  186. // hjL.font = [UIFont boldSystemFontOfSize:18];
  187. // hjL.textColor = UIColor.whiteColor;
  188. // hjL.text = @"合集";
  189. // UIImageView *mImgView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-27, 13.5, 11, 11)];
  190. // mImgView.image = [UIImage imageNamed:@"Frame 9366"];
  191. // [bottomView addSubview:mImgView];
  192. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showHJ:)];
  193. // [bottomView addGestureRecognizer:tap];
  194. //
  195. // UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(16,34, SCREEN_WIDTH-32, 2)];
  196. // [bottomView addSubview:slider];
  197. // slider.maximumValue = 1;
  198. // slider.minimumValue = 0;
  199. // [slider setThumbImage:[UIImage imageNamed:@"b_jdt.png"] forState:UIControlStateNormal];
  200. // [slider setThumbImage:[UIImage imageNamed:@"b_jdtb.png"] forState:UIControlStateHighlighted];
  201. // [slider setMinimumTrackImage:[UIImage imageNamed:@"jdt.png"] forState:UIControlStateNormal];
  202. // [slider setMinimumTrackImage:[UIImage imageNamed:@"jdt.png"] forState:UIControlStateHighlighted];
  203. // [slider setMaximumTrackImage:[UIImage imageNamed:@"jdt.png"] forState:UIControlStateNormal];
  204. // [slider setMaximumTrackImage:[UIImage imageNamed:@"jdt.png"] forState:UIControlStateHighlighted] ;
  205. // [slider setMinimumTrackTintColor:COLOR(0, 0, 0, 0.1)];
  206. // [slider setMaximumTrackTintColor:COLOR(0, 0, 0, 0.1)];
  207. // slider.alpha = 0.6;
  208. // self.videoSlider = slider;
  209. //
  210. // UILabel *descLabel = [[UILabel alloc] init];
  211. // descLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
  212. // descLabel.textColor = [UIColor whiteColor];
  213. // descLabel.numberOfLines = 2;
  214. // [cell.contentView addSubview:descLabel];
  215. // [cell.contentView bringSubviewToFront:descLabel];
  216. // [descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  217. // make.bottom.equalTo(bottomView.mas_top).offset(-15);
  218. // make.left.equalTo(cell.contentView).offset(16);
  219. // make.width.mas_equalTo(SCREEN_WIDTH - 90);
  220. // }];
  221. //
  222. // UILabel *titleLabel = [[UILabel alloc] init];
  223. // titleLabel.font = [UIFont boldSystemFontOfSize:18];
  224. // titleLabel.textColor = [UIColor whiteColor];
  225. // titleLabel.numberOfLines = 2;
  226. // [cell.contentView addSubview:titleLabel];
  227. // [cell.contentView bringSubviewToFront:titleLabel];
  228. // [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  229. // make.bottom.equalTo(descLabel.mas_top).offset(-12.5);
  230. // make.left.equalTo(cell.contentView).offset(16);
  231. // make.width.mas_equalTo(SCREEN_WIDTH - 90);
  232. // }];
  233. //
  234. // JXEpisode *episode = self.episodes[indexPath.item];
  235. // titleLabel.text = self.drama.title ?: @"";
  236. // descLabel.text = episode.title ?: @"";
  237. //
  238. // // 播放视频
  239. // [player playWithAppId:episode.appId fileId:episode.fileId psign:episode.psign];
  240. //
  241. // return cell;
  242. //}
  243. -(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
  244. VideoDetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass(VideoDetailCell.class) forIndexPath:indexPath];
  245. // 设置代理
  246. cell.delegate = self;
  247. NSLog(@"[JXShortDrama] ✅ cellForItemAtIndexPath - Cell delegate 已设置,index: %ld", (long)indexPath.item);
  248. // 配置数据
  249. JXEpisode *episode = self.episodes[indexPath.item];
  250. [cell configureWithDrama:episode andDiction:self.interaction andTitle:self.drama.title];
  251. return cell;
  252. }
  253. - (void)showHJ:(UIGestureRecognizer *)gtr{
  254. JXEpisode *episode = self.episodes[self.currentEpisodeIndex];
  255. [self showCollectionDialogWithDramaId:[NSString stringWithFormat:@"%ld",episode.dramaId]];
  256. }
  257. - (void)showCollectionDialogWithDramaId:(NSString *)dramaId {
  258. JXCollectionViewController *collectionVC = [[JXCollectionViewController alloc] initWithDramaId:dramaId];
  259. collectionVC.delegate = self;
  260. // 设置弹窗样式(底部弹出)
  261. if (@available(iOS 15.0, *)) {
  262. UISheetPresentationController *sheet = collectionVC.sheetPresentationController;
  263. sheet.detents = @[
  264. [UISheetPresentationControllerDetent mediumDetent],
  265. [UISheetPresentationControllerDetent largeDetent]
  266. ];
  267. sheet.prefersGrabberVisible = YES;
  268. }
  269. [self presentViewController:collectionVC animated:YES completion:nil];
  270. }
  271. - (void)commentDidClicked{
  272. JXEpisode *episode = self.episodes[self.currentEpisodeIndex];
  273. JXCommentViewController *commentVC = [[JXCommentViewController alloc] initWithDramaId:[NSString stringWithFormat:@"%ld",episode.dramaId]];
  274. // 设置弹窗样式(底部弹出)
  275. if (@available(iOS 15.0, *)) {
  276. UISheetPresentationController *sheet = commentVC.sheetPresentationController;
  277. sheet.detents = @[
  278. [UISheetPresentationControllerDetent mediumDetent],
  279. [UISheetPresentationControllerDetent largeDetent]
  280. ];
  281. sheet.prefersGrabberVisible = YES;
  282. }
  283. [self presentViewController:commentVC animated:YES completion:^{
  284. NSLog(@"[JXShortDrama] 🗨️ commentVC present 完成!");
  285. }];
  286. }
  287. - (void)shortDramaCellDidTapComment:(UICollectionViewCell *)cell {
  288. [self commentDidClicked];
  289. }
  290. - (void)shortDramaCellDidTapCollection:(UICollectionViewCell *)cell {
  291. JXCollectionViewController *collectionVC = [[JXCollectionViewController alloc] initWithDramaId:self.dramaId];
  292. collectionVC.delegate = self;
  293. // 设置弹窗样式(底部弹出)
  294. if (@available(iOS 15.0, *)) {
  295. UISheetPresentationController *sheet = collectionVC.sheetPresentationController;
  296. sheet.detents = @[
  297. [UISheetPresentationControllerDetent mediumDetent],
  298. [UISheetPresentationControllerDetent largeDetent]
  299. ];
  300. sheet.prefersGrabberVisible = YES;
  301. }
  302. [self presentViewController:collectionVC animated:YES completion:nil];
  303. }
  304. - (void)superPlayerDidUpdateProgress:(NSTimeInterval)currentTime duration:(NSTimeInterval)duration {
  305. // 播放进度更新(可用于显示进度条)
  306. // NSLog(@"[JXShortDramaCell] 播放进度: %.1f / %.1f", currentTime, duration);
  307. float progress = currentTime/duration;
  308. self.videoSlider.value = progress;
  309. }
  310. - (void)collectionViewControllerDidSelectEpisode:(NSString *)episodeId {
  311. NSLog(@"[JXShortDrama] 选择播放剧集: %@", episodeId);
  312. // TODO: 切换到选定的剧集播放
  313. // 可以找到对应的短剧,然后滚动到该位置并播放
  314. }
  315. #pragma mark - UICollectionViewDelegate
  316. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  317. // 获取当前可见的cell索引
  318. CGFloat pageWidth = scrollView.frame.size.width;
  319. CGFloat pageHeight = scrollView.frame.size.height;
  320. NSInteger currentPage = (NSInteger)(scrollView.contentOffset.y / pageHeight);
  321. if (currentPage != self.currentEpisodeIndex) {
  322. [self stopVideoAtIndex:self.currentEpisodeIndex];
  323. // 播放新视频
  324. self.currentEpisodeIndex = currentPage;
  325. [self playVideoAtIndex:currentPage];
  326. }else{
  327. [self resumeCurrentVideo];
  328. }
  329. }
  330. - (void)playVideoAtIndex:(NSInteger)index {
  331. if (index < 0 || index >= self.episodes.count) {
  332. return;
  333. }
  334. [self doPlayVideoAtIndex:index];
  335. }
  336. - (void)doPlayVideoAtIndex:(NSInteger)index {
  337. // 启动播放
  338. VideoDetailCell *cell = (VideoDetailCell *)[self.episodeCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
  339. if (cell) {
  340. [cell startPlay];
  341. }
  342. }
  343. - (void)stopVideoAtIndex:(NSInteger)index {
  344. if (index < 0 || index >= self.episodes.count) {
  345. return;
  346. }
  347. VideoDetailCell *cell = (VideoDetailCell *)[self.episodeCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
  348. [cell stopPlay];
  349. }
  350. - (void)pauseCurrentVideo {
  351. if (self.currentEpisodeIndex < 0 || self.currentEpisodeIndex >= self.episodes.count) {
  352. return;
  353. }
  354. VideoDetailCell *cell = (VideoDetailCell *)[self.episodeCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentEpisodeIndex inSection:0]];
  355. [cell pausePlay];
  356. }
  357. - (void)resumeCurrentVideo {
  358. if (self.currentEpisodeIndex < 0 || self.currentEpisodeIndex >= self.episodes.count) {
  359. return;
  360. }
  361. VideoDetailCell *cell = (VideoDetailCell *)[self.episodeCollectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:self.currentEpisodeIndex inSection:0]];
  362. [cell resumePlay];
  363. }
  364. - (void)pauseAllVideos {
  365. // 暂停所有可见的Cell
  366. for (NSIndexPath *indexPath in self.episodeCollectionView.indexPathsForVisibleItems) {
  367. VideoDetailCell *cell = (VideoDetailCell *)[self.episodeCollectionView cellForItemAtIndexPath:indexPath];
  368. [cell pausePlay];
  369. }
  370. }
  371. #pragma mark - Helper Methods
  372. - (void)setupInteractionButtonsForCell:(UICollectionViewCell *)cell {
  373. CGFloat width = cell.contentView.bounds.size.width;
  374. UIView *container = [[UIView alloc] initWithFrame:CGRectMake(width - 48, kScreenHeight - safebottom - 190 - 90, 32, 190)];
  375. [cell.contentView addSubview:container];
  376. // 点赞
  377. UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  378. likeButton.frame = CGRectMake(0, 0, 32, 32);
  379. [likeButton setImage:[UIImage imageNamed:@"icon 1.1"] forState:UIControlStateNormal];
  380. [likeButton setImage:[UIImage imageNamed:@"icon 1.5"] forState:UIControlStateSelected];
  381. [container addSubview:likeButton];
  382. UILabel *likeCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 32, 18)];
  383. likeCountLabel.textAlignment = NSTextAlignmentCenter;
  384. likeCountLabel.font = [UIFont systemFontOfSize:12];
  385. likeCountLabel.textColor = [UIColor whiteColor];
  386. likeCountLabel.text = [self formatCount:self.interaction.likeCount];
  387. [container addSubview:likeCountLabel];
  388. // 收藏
  389. UIButton *favoriteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  390. favoriteButton.frame = CGRectMake(0, CGRectGetMaxY(likeCountLabel.frame) + 20, 32, 32);
  391. [favoriteButton setImage:[UIImage imageNamed:@"icon 1.2"] forState:UIControlStateNormal];
  392. [favoriteButton setImage:[UIImage imageNamed:@"icon 1.5"] forState:UIControlStateSelected];
  393. [container addSubview:favoriteButton];
  394. UILabel *favoriteCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(favoriteButton.frame), 32, 18)];
  395. favoriteCountLabel.textAlignment = NSTextAlignmentCenter;
  396. favoriteCountLabel.font = [UIFont systemFontOfSize:12];
  397. favoriteCountLabel.textColor = [UIColor whiteColor];
  398. favoriteCountLabel.text = [self formatCount:self.interaction.favoriteCount];
  399. [container addSubview:favoriteCountLabel];
  400. // 评论
  401. UIButton *commentButton = [UIButton buttonWithType:UIButtonTypeCustom];
  402. commentButton.frame = CGRectMake(0, CGRectGetMaxY(favoriteCountLabel.frame) + 20, 32, 32);
  403. [commentButton setImage:[UIImage imageNamed:@"icon 1.3"] forState:UIControlStateNormal];
  404. [container addSubview:commentButton];
  405. [commentButton addTarget:self action:@selector(commentDidClicked) forControlEvents:UIControlEventTouchUpInside];
  406. UILabel *commentCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(commentButton.frame) , 32, 18)];
  407. commentCountLabel.textAlignment = NSTextAlignmentCenter;
  408. commentCountLabel.font = [UIFont systemFontOfSize:12];
  409. commentCountLabel.textColor = [UIColor whiteColor];
  410. commentCountLabel.text = [self formatCount:self.interaction.commentCount];
  411. [container addSubview:commentCountLabel];
  412. }
  413. - (NSString *)formatCount:(long long)count {
  414. if (count >= 1000000) {
  415. return [NSString stringWithFormat:@"%.1fM", count / 1000000.0];
  416. } else if (count >= 1000) {
  417. return [NSString stringWithFormat:@"%.1fK", count / 1000.0];
  418. }
  419. return [NSString stringWithFormat:@"%lld", count];
  420. }
  421. - (void)dealloc {
  422. // 停止所有播放器
  423. }
  424. - (NSMutableArray *)playerList{
  425. if (!_playerList) {
  426. _playerList = [NSMutableArray array];
  427. }
  428. return _playerList;
  429. }
  430. @end