HMVideoPlayerViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. }
  121. -(void)endPlay{
  122. [self.videoView destoryPlayer];
  123. }
  124. - (void)pausePlay{
  125. [self.videoView pause];
  126. }
  127. - (void)resumePlay{
  128. if (self.videoView.player.status == HMVideoPlayerStatusPaused) {
  129. [self.videoView resume];
  130. }else{
  131. [self.videoView playVideoFrom:self.videoView.currentPlayView];
  132. }
  133. }
  134. - (void)videoViewDidClickOneOnOne:(HMVideoView *)videoView{
  135. //点击了一对一按钮
  136. }
  137. - (void)videoViewDidClickRecharge:(HMVideoView *)videoView{
  138. [self.rechargePopView show:[UIApplication sharedApplication].keyWindow type:FDPopTypeBottom];
  139. // if (!self.mgRechargeView) {
  140. // self.mgRechargeView = [[MGLiveRechargeView alloc]initWithFrame:CGRectMake(0, kScreenH - kRealValue(485), kScreenW, kRealValue(485))];
  141. // }
  142. // [self.mgRechargeView show:self.view];
  143. // NSLog(@"%s",__func__);
  144. // self.rechargeView.hidden = NO;
  145. // SUS_WINDOW.window_Tap_Ges.enabled = NO;
  146. // SUS_WINDOW.window_Pan_Ges.enabled = NO;
  147. // [self.rechargeView loadRechargeData];
  148. //
  149. // FWWeakify(self)
  150. // [UIView animateWithDuration:0.5 animations:^{
  151. //
  152. // FWStrongify(self)
  153. // self.rechargeView.transform = CGAffineTransformMakeTranslation(0, (kScreenH-kRechargeViewHeight)/2-kScreenH);
  154. //
  155. // } completion:^(BOOL finished) {
  156. //
  157. // }];
  158. }
  159. - (void)videoViewDidClickReport:(HMVideoView *)videoView{
  160. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  161. [alert addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"举报") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  162. [videoView clickShareViewReportBtn];
  163. }]];
  164. [alert addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"取消") style:UIAlertActionStyleCancel handler:nil]];
  165. [self presentViewController:alert animated:YES completion:nil];
  166. }
  167. //点击视频view
  168. -(void)controlViewDidClickSelf:(HMVideoView *)videoView{
  169. // if (videoView.giftView.hidden == NO) {
  170. // self.rechargeView.hidden = YES;
  171. // return;
  172. // }
  173. if (self.rechargeView.hidden == NO) {
  174. self.rechargeView.hidden = YES;
  175. videoView.giftView.hidden = NO;
  176. return;
  177. }
  178. videoView.giftView.hidden = YES;
  179. }
  180. -(void)deleteVideoWithView:(HMVideoView *)videoView{
  181. [self.videoView destoryPlayer];
  182. if (self.isRefreshVideoBlock) {
  183. self.isRefreshVideoBlock(YES);
  184. [[AppDelegate sharedAppDelegate]popViewController];
  185. }
  186. }
  187. //关闭
  188. -(void)closeRechargeWithRechargeView:(RechargeView *)rechargeView{
  189. self.rechargeView.hidden = YES;
  190. // [[AppDelegate sharedAppDelegate]popViewController];
  191. }
  192. - (void)pushToNextViewController:(NSString *)user_id {
  193. // NSString *user_id = noti.object;
  194. SHomePageVC *tmpController= [[SHomePageVC alloc]init];
  195. tmpController.user_id = user_id;
  196. tmpController.type = 0;
  197. [[AppDelegate sharedAppDelegate]pushViewController:tmpController animated:YES];
  198. [self.videoView.player pausePlay];
  199. }
  200. - (void)popToRootViewController{
  201. [self.navigationController popViewControllerAnimated:YES];
  202. [[NSNotificationCenter defaultCenter]removeObserver:self];
  203. [self.videoView destoryPlayer];
  204. }
  205. /*
  206. #pragma mark - Navigation
  207. // In a storyboard-based application, you will often want to do a little preparation before navigation
  208. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  209. // Get the new view controller using [segue destinationViewController].
  210. // Pass the selected object to the new view controller.
  211. }
  212. */
  213. - (void)dealloc {
  214. [self.videoView destoryPlayer];
  215. NSLog(@"playerVC dealloc");
  216. }
  217. #pragma mark ------------- Lazy Load --------------
  218. - (HMVideoView *)videoView{
  219. if (!_videoView) {
  220. _videoView = [[HMVideoView alloc]initWithVC:self isPushed:self.isPushed requestDict:self.dict];
  221. _videoView.delegate = self;
  222. _videoView.isRecommend = YES;
  223. _videoView.clickHeadBlock = ^(NSString * _Nonnull userID) {
  224. [self pushToNextViewController:userID];
  225. };
  226. }
  227. return _videoView;
  228. }
  229. - (RechargeView *)rechargeView
  230. {
  231. if (_rechargeView == nil)
  232. {
  233. _rechargeView = [[RechargeView alloc] initWithFrame:CGRectMake(kRechargeMargin, kScreenH, kScreenW-2*kRechargeMargin, kRechargeViewHeight) andUIViewController:self];
  234. _rechargeView.hidden = YES;
  235. _rechargeView.delegate = self;
  236. }
  237. return _rechargeView;
  238. }
  239. - (UIStatusBarStyle)preferredStatusBarStyle{
  240. return UIStatusBarStyleLightContent;
  241. }
  242. - (BogoRechargePopView *)rechargePopView{
  243. if (!_rechargePopView) {
  244. _rechargePopView = [[BogoRechargePopView alloc]initWithFrame:CGRectMake(0, kScreenH, kScreenW, kScreenH - kRealValue(180))];
  245. }
  246. return _rechargePopView;
  247. }
  248. @end