ZFADControlView.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // ZFADControlView.m
  3. // ZFPlayer_Example
  4. //
  5. // Created by 紫枫 on 2019/5/15.
  6. // Copyright © 2019 紫枫. All rights reserved.
  7. //
  8. // Temporarily disable third-party advertising module
  9. #if 0
  10. #import "ZFADControlView.h"
  11. #import <ZFPlayer/UIView+ZFFrame.h>
  12. #import <ZFPlayer/ZFUtilities.h>
  13. #import <ZFPlayer/ZFPlayerController.h>
  14. @interface ZFADControlView ()
  15. @property (nonatomic, strong) UIImageView *bgImgView;
  16. @property (nonatomic, strong) UIButton *skipBtn;
  17. @property (nonatomic, strong) UIButton *fullScreenBtn;
  18. @end
  19. @implementation ZFADControlView
  20. @synthesize player = _player;
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. [self addSubview:self.skipBtn];
  25. [self addSubview:self.fullScreenBtn];
  26. }
  27. return self;
  28. }
  29. - (void)layoutSubviews {
  30. [super layoutSubviews];
  31. CGFloat min_x = 0;
  32. CGFloat min_y = 0;
  33. CGFloat min_w = 0;
  34. CGFloat min_h = 0;
  35. CGFloat min_view_w = self.zf_width;
  36. CGFloat min_view_h = self.bounds.size.height;
  37. self.bgImgView.frame = self.bounds;
  38. min_x = min_view_w - 100;
  39. min_y = 20;
  40. min_w = 70;
  41. min_h = 30;
  42. self.skipBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  43. self.skipBtn.layer.cornerRadius = min_h/2;
  44. self.skipBtn.layer.masksToBounds = YES;
  45. min_w = 30;
  46. min_h = min_w;
  47. min_x = min_view_w - min_w - 20;
  48. min_y = min_view_h - min_h - 20;
  49. self.fullScreenBtn.frame = CGRectMake(min_x, min_y, min_w, min_h);
  50. self.fullScreenBtn.layer.cornerRadius = min_h/2;
  51. self.fullScreenBtn.layer.masksToBounds = YES;
  52. }
  53. - (void)skipBtnClick {
  54. if (self.skipCallback) self.skipCallback();
  55. }
  56. - (void)fullScreenBtnClick {
  57. if (self.fullScreenCallback) self.fullScreenCallback();
  58. }
  59. /// 加载状态改变
  60. - (void)videoPlayer:(ZFPlayerController *)videoPlayer loadStateChanged:(ZFPlayerLoadState)state {
  61. if (state == ZFPlayerLoadStatePrepare) {
  62. self.bgImgView.hidden = NO;
  63. } else if (state == ZFPlayerLoadStatePlaythroughOK || state == ZFPlayerLoadStatePlayable) {
  64. self.bgImgView.hidden = YES;
  65. }
  66. }
  67. /// 播放进度改变回调
  68. - (void)videoPlayer:(ZFPlayerController *)videoPlayer currentTime:(NSTimeInterval)currentTime totalTime:(NSTimeInterval)totalTime {
  69. NSString *title = [NSString stringWithFormat:@"跳过 %zd秒",(NSInteger)(totalTime-currentTime)];
  70. [self.skipBtn setTitle:title forState:UIControlStateNormal];
  71. }
  72. - (void)videoPlayer:(ZFPlayerController *)videoPlayer orientationWillChange:(ZFOrientationObserver *)observer {
  73. self.fullScreenBtn.selected = observer.isFullScreen;
  74. }
  75. - (void)gestureSingleTapped:(ZFPlayerGestureControl *)gestureControl {
  76. }
  77. - (void)setPlayer:(ZFPlayerController *)player {
  78. _player = player;
  79. player.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFill;
  80. [player.currentPlayerManager.view insertSubview:self.bgImgView atIndex:0];
  81. }
  82. - (UIImageView *)bgImgView {
  83. if (!_bgImgView) {
  84. _bgImgView = [[UIImageView alloc] init];
  85. _bgImgView.userInteractionEnabled = YES;
  86. }
  87. return _bgImgView;
  88. }
  89. - (UIButton *)skipBtn {
  90. if (!_skipBtn) {
  91. _skipBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  92. _skipBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  93. [_skipBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  94. _skipBtn.titleLabel.font = [UIFont systemFontOfSize:13];
  95. [_skipBtn addTarget:self action:@selector(skipBtnClick) forControlEvents:UIControlEventTouchUpInside];
  96. }
  97. return _skipBtn;
  98. }
  99. - (UIButton *)fullScreenBtn {
  100. if (!_fullScreenBtn) {
  101. _fullScreenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  102. [_fullScreenBtn setImage:ZFPlayer_Image(@"ZFPlayer_fullscreen") forState:UIControlStateNormal];
  103. [_fullScreenBtn setImage:ZFPlayer_Image(@"ZFPlayer_shrinkscreen") forState:UIControlStateSelected];
  104. [_fullScreenBtn addTarget:self action:@selector(fullScreenBtnClick) forControlEvents:UIControlEventTouchUpInside];
  105. _fullScreenBtn.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  106. }
  107. return _fullScreenBtn;
  108. }
  109. @end
  110. #endif