JXDetailViewController.m 21 KB

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