HMVideoPlayerViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. //
  2. // HMRecomendViewController.m
  3. // BuguLive
  4. //
  5. // Created by 范东 on 2018/12/27.
  6. // Copyright © 2018 xfg. All rights reserved.
  7. //
  8. #import "HMVideoPlayerViewController.h"
  9. #import "SmallVideoListModel.h"
  10. #import "RechargeView.h"
  11. #import "BogoRechargePopView.h"
  12. @interface HMVideoPlayerViewController ()<UIGestureRecognizerDelegate,HMVideoViewDelegate,RechargeViewDelegate>
  13. @property (nonatomic, strong) SmallVideoListModel *model;
  14. @property (nonatomic, strong) NSArray *videos;
  15. @property (nonatomic, assign) NSInteger playIndex;
  16. @property (nonatomic, assign) BOOL isPushed;
  17. @property (nonatomic, strong) NSDictionary *dict;
  18. @property (nonatomic, strong) UIButton *moreBtn;
  19. @property(nonatomic, strong) RechargeView *rechargeView;
  20. @property(nonatomic, strong) BogoRechargePopView *rechargePopView;
  21. @end
  22. @implementation HMVideoPlayerViewController
  23. - (instancetype)initWithVideoModel:(SmallVideoListModel *)model {
  24. if (self = [super init]) {
  25. self.model = model;
  26. }
  27. return self;
  28. }
  29. - (instancetype)initWithVideos:(NSArray *)videos index:(NSInteger)index IsPushed:(BOOL)isPushed requestDict:(nonnull NSDictionary *)dict{
  30. if (self = [super init]) {
  31. self.videos = videos;
  32. self.playIndex = index;
  33. self.isPushed = isPushed;
  34. self.dict = dict;
  35. }
  36. return self;
  37. }
  38. - (void)viewWillAppear:(BOOL)animated{
  39. [super viewWillAppear:animated];
  40. [self.navigationController setNavigationBarHidden:YES animated:animated];
  41. if (self.isPushed) {
  42. // [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:animated];
  43. }
  44. // id traget = self.navigationController.interactivePopGestureRecognizer.delegate;
  45. // UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:traget action:nil];
  46. // [self.view addGestureRecognizer:pan];
  47. if (self.videoView.player) {
  48. [self.videoView.player resumePlay];
  49. }
  50. [self setNeedsStatusBarAppearanceUpdate];
  51. self.isViewAppear = YES;
  52. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
  53. }
  54. - (void)setIsViewAppear:(BOOL)isViewAppear{
  55. _isViewAppear = isViewAppear;
  56. if (isViewAppear) {
  57. if (self.videoView.player) {
  58. [self.videoView.player resumePlay];
  59. }
  60. }else{
  61. if (self.videoView.player) {
  62. [self.videoView.player pausePlay];
  63. }
  64. }
  65. }
  66. - (void)viewWillDisappear:(BOOL)animated {
  67. [super viewWillDisappear:animated];
  68. if (self.videoView.player) {
  69. [self.videoView.player pausePlay];
  70. }
  71. self.isViewAppear = NO;
  72. }
  73. - (void)viewDidLoad {
  74. [super viewDidLoad];
  75. // Do any additional setup after loading the view.
  76. self.view.backgroundColor = kClearColor;
  77. [self.view addSubview:self.videoView];
  78. self.videoView.frame = CGRectMake(0, 0, kScreenW, kScreenH);
  79. self.videoView.backgroundColor = kClearColor;
  80. self.videoView.delegate = self;
  81. if (self.videos.count) {
  82. [self.videoView setModels:self.videos index:self.playIndex];
  83. }else{
  84. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  85. [parmDict setObject:@"svideo" forKey:@"ctl"];
  86. [parmDict setObject:@"recommit_list" forKey:@"act"];
  87. // [parmDict setObject:@"video" forKey:@"act"];
  88. [parmDict setObject:[NSNumber numberWithInt:1] forKey:@"page"];
  89. FWWeakify(self)
  90. [self.httpsManager POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  91. FWStrongify(self)
  92. if ([responseJson toInt:@"status"] == 1)
  93. {
  94. NSArray *list = responseJson[@"data"];
  95. NSMutableArray *tempArray = [NSMutableArray array];
  96. for ( NSDictionary *dict in list)
  97. {
  98. SmallVideoListModel *model = [SmallVideoListModel mj_objectWithKeyValues:dict];
  99. [tempArray addObject:model];
  100. }
  101. self.videos = tempArray;
  102. [self.videoView setModels:self.videos index:self.playIndex];
  103. }
  104. } FailureBlock:^(NSError *error) {
  105. }];
  106. }
  107. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  108. if (self.isPushed) {
  109. // 添加返回按钮
  110. UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(kStatusBarHeight / 2, kStatusBarHeight, 44, 44)];
  111. [backButton setImage:[UIImage imageNamed:@"ac_auction_back"] forState:UIControlStateNormal];
  112. [backButton addTarget:self action:@selector(popToRootViewController) forControlEvents:UIControlEventTouchUpInside];
  113. [self.view addSubview:backButton];
  114. }
  115. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlay) name:UIApplicationWillResignActiveNotification object:nil];
  116. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resumePlay) name:UIApplicationDidBecomeActiveNotification object:nil];
  117. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pausePlay) name:@"MSG_VIDEO_LINE_CALL" object:nil];
  118. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPlay) name:KLOGIN_OUT_Notification object:nil];
  119. [self.view addSubview:self.rechargeView];
  120. [self.videoView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.edges.equalTo(self.view);
  122. }];
  123. }
  124. -(void)endPlay{
  125. [self.videoView destoryPlayer];
  126. }
  127. - (void)pausePlay{
  128. [self.videoView pause];
  129. }
  130. - (void)resumePlay{
  131. if (self.videoView.player.status == HMVideoPlayerStatusPaused) {
  132. [self.videoView resume];
  133. }else{
  134. [self.videoView playVideoFrom:self.videoView.currentPlayView];
  135. }
  136. }
  137. - (void)videoViewDidClickOneOnOne:(HMVideoView *)videoView{
  138. //点击了一对一按钮
  139. }
  140. - (void)videoViewDidClickRecharge:(HMVideoView *)videoView{
  141. [self.rechargePopView show:[UIApplication sharedApplication].keyWindow type:FDPopTypeBottom];
  142. // if (!self.mgRechargeView) {
  143. // self.mgRechargeView = [[MGLiveRechargeView alloc]initWithFrame:CGRectMake(0, kScreenH - kRealValue(485), kScreenW, kRealValue(485))];
  144. // }
  145. // [self.mgRechargeView show:self.view];
  146. // NSLog(@"%s",__func__);
  147. // self.rechargeView.hidden = NO;
  148. // SUS_WINDOW.window_Tap_Ges.enabled = NO;
  149. // SUS_WINDOW.window_Pan_Ges.enabled = NO;
  150. // [self.rechargeView loadRechargeData];
  151. //
  152. // FWWeakify(self)
  153. // [UIView animateWithDuration:0.5 animations:^{
  154. //
  155. // FWStrongify(self)
  156. // self.rechargeView.transform = CGAffineTransformMakeTranslation(0, (kScreenH-kRechargeViewHeight)/2-kScreenH);
  157. //
  158. // } completion:^(BOOL finished) {
  159. //
  160. // }];
  161. }
  162. - (void)videoViewDidClickReport:(HMVideoView *)videoView{
  163. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  164. [alert addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"举报") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  165. [videoView clickShareViewReportBtn];
  166. }]];
  167. [alert addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:nil]];
  168. [self presentViewController:alert animated:YES completion:nil];
  169. }
  170. //点击视频view
  171. -(void)controlViewDidClickSelf:(HMVideoView *)videoView{
  172. // if (videoView.giftView.hidden == NO) {
  173. // self.rechargeView.hidden = YES;
  174. // return;
  175. // }
  176. if (self.rechargeView.hidden == NO) {
  177. self.rechargeView.hidden = YES;
  178. videoView.giftView.hidden = NO;
  179. return;
  180. }
  181. videoView.giftView.hidden = YES;
  182. }
  183. -(void)deleteVideoWithView:(HMVideoView *)videoView{
  184. [self.videoView destoryPlayer];
  185. if (self.isRefreshVideoBlock) {
  186. self.isRefreshVideoBlock(YES);
  187. [[AppDelegate sharedAppDelegate]popViewController];
  188. }
  189. }
  190. //关闭
  191. -(void)closeRechargeWithRechargeView:(RechargeView *)rechargeView{
  192. self.rechargeView.hidden = YES;
  193. // [[AppDelegate sharedAppDelegate]popViewController];
  194. }
  195. - (void)pushToNextViewController:(NSString *)user_id {
  196. // NSString *user_id = noti.object;
  197. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  198. tmpController.user_id = user_id;
  199. tmpController.type = 0;
  200. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  201. [self.videoView.player pausePlay];
  202. }
  203. - (void)popToRootViewController{
  204. [self.navigationController popViewControllerAnimated:YES];
  205. [[NSNotificationCenter defaultCenter]removeObserver:self];
  206. [self.videoView destoryPlayer];
  207. }
  208. /*
  209. #pragma mark - Navigation
  210. // In a storyboard-based application, you will often want to do a little preparation before navigation
  211. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  212. // Get the new view controller using [segue destinationViewController].
  213. // Pass the selected object to the new view controller.
  214. }
  215. */
  216. - (void)dealloc {
  217. [self.videoView destoryPlayer];
  218. NSLog(@"playerVC dealloc");
  219. }
  220. #pragma mark ------------- Lazy Load --------------
  221. - (HMVideoView *)videoView{
  222. if (!_videoView) {
  223. _videoView = [[HMVideoView alloc]initWithVC:self isPushed:self.isPushed requestDict:self.dict];
  224. _videoView.delegate = self;
  225. _videoView.isRecommend = YES;
  226. _videoView.clickHeadBlock = ^(NSString * _Nonnull userID) {
  227. [self pushToNextViewController:userID];
  228. };
  229. }
  230. return _videoView;
  231. }
  232. - (RechargeView *)rechargeView
  233. {
  234. if (_rechargeView == nil)
  235. {
  236. _rechargeView = [[RechargeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, kRechargeViewHeight) andUIViewController:self];
  237. _rechargeView.hidden = YES;
  238. _rechargeView.delegate = self;
  239. }
  240. return _rechargeView;
  241. }
  242. - (UIStatusBarStyle)preferredStatusBarStyle{
  243. return UIStatusBarStyleLightContent;
  244. }
  245. - (BogoRechargePopView *)rechargePopView{
  246. if (!_rechargePopView) {
  247. _rechargePopView = [[BogoRechargePopView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH - kRealValue(180))];
  248. }
  249. return _rechargePopView;
  250. }
  251. @end