ZFPlayerDetailViewController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // ZFPlayerDetailViewController.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 紫枫 on 2018/9/12.
  6. // Copyright © 2018年 紫枫. All rights reserved.
  7. // 视频详情页
  8. #import "ZFPlayerDetailViewController.h"
  9. #import <ZFPlayer/ZFAVPlayerManager.h>
  10. #import <ZFPlayer/ZFIJKPlayerManager.h>
  11. #import <ZFPlayer/ZFPlayerControlView.h>
  12. #import "ZFSmallPlayViewController.h"
  13. #import "UIImageView+ZFCache.h"
  14. #import "ZFUtilities.h"
  15. static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
  16. @interface ZFPlayerDetailViewController ()
  17. @property (nonatomic, strong) UIImageView *containerView;
  18. @property (nonatomic, strong) UIButton *playBtn;
  19. @end
  20. @implementation ZFPlayerDetailViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. [self.view addSubview:self.containerView];
  25. [self.containerView addSubview:self.playBtn];
  26. [self.player addPlayerViewToContainerView:self.containerView];
  27. }
  28. - (void)viewWillLayoutSubviews {
  29. [super viewWillLayoutSubviews];
  30. CGFloat x = 0;
  31. CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  32. CGFloat w = CGRectGetWidth(self.view.frame);
  33. CGFloat h = w*9/16;
  34. self.containerView.frame = CGRectMake(x, y, w, h);
  35. w = 44;
  36. h = w;
  37. x = (CGRectGetWidth(self.containerView.frame)-w)/2;
  38. y = (CGRectGetHeight(self.containerView.frame)-h)/2;
  39. self.playBtn.frame = CGRectMake(x, y, w, h);
  40. }
  41. - (void)didMoveToParentViewController:(UIViewController *)parent {
  42. if (!parent) {
  43. if (self.detailVCPopCallback) {
  44. self.detailVCPopCallback();
  45. }
  46. }
  47. }
  48. - (void)playClick:(UIButton *)sender {
  49. if (self.detailVCPlayCallback) {
  50. self.detailVCPlayCallback();
  51. }
  52. [self.player addPlayerViewToContainerView:self.containerView];
  53. }
  54. - (UIStatusBarStyle)preferredStatusBarStyle {
  55. if (self.player.isFullScreen) {
  56. return UIStatusBarStyleLightContent;
  57. }
  58. return UIStatusBarStyleDefault;
  59. }
  60. - (BOOL)prefersStatusBarHidden {
  61. return NO;
  62. }
  63. - (BOOL)shouldAutorotate {
  64. return NO;
  65. }
  66. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  67. return UIInterfaceOrientationMaskPortrait;
  68. }
  69. - (UIImageView *)containerView {
  70. if (!_containerView) {
  71. _containerView = [UIImageView new];
  72. [_containerView setImageWithURLString:kVideoCover placeholder:[ZFUtilities imageWithColor:[UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1] size:CGSizeMake(1, 1)]];
  73. }
  74. return _containerView;
  75. }
  76. - (UIButton *)playBtn {
  77. if (!_playBtn) {
  78. _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  79. [_playBtn setImage:[UIImage imageNamed:@"new_allPlay_44x44_"] forState:UIControlStateNormal];
  80. [_playBtn addTarget:self action:@selector(playClick:) forControlEvents:UIControlEventTouchUpInside];
  81. }
  82. return _playBtn;
  83. }
  84. @end