videoPlayByAVPlayerViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. //
  2. // videoPlayByAVPlayerViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/22.
  6. //
  7. #import "videoPlayByAVPlayerViewController.h"
  8. #import "previewVideoPortraitTopMoreView.h"
  9. #import "editShareView.h"
  10. #import "uploadFileRecordViewController.h"
  11. #import "previewVideoLandscapeTopMoreView.h"
  12. #import "UIInterface+HXRotation.h"
  13. //#import <ZFPlayer/ZFAVPlayerManager.h>
  14. //#import <ZFPlayer/ZFIJKPlayerManager.h>
  15. //#import <ZFPlayer/ZFPlayerControlView.h>
  16. //#import <ZFPlayer/ZFPlayerConst.h>
  17. //#import "ZFUtilities.h"
  18. #import "ZFAVPlayerManager.h"
  19. #import "ZFIJKPlayerManager.h"
  20. #import "ZFPlayerControlView.h"
  21. #import "ZFPlayerConst.h"
  22. #import "ZFUtilities.h"
  23. #import "lastFileManager.h"
  24. #import "DFPlayer.h"
  25. @interface videoPlayByAVPlayerViewController ()
  26. @property (nonatomic, strong) ZFPlayerController *player;
  27. @property (nonatomic, strong) ZFPlayerControlView *controlView;
  28. @property (nonatomic, strong)ZFAVPlayerManager *playerManager;
  29. @property (nonatomic, strong)UIView *bgView;
  30. @property (nonatomic, strong)UIButton *portraitBackBtn;
  31. @property (nonatomic, strong)UIButton *portraitToLandScapeBtn;
  32. @property (nonatomic, strong)UIButton *portraitTopMoreBtn;
  33. @property (nonatomic, strong)previewVideoPortraitTopMoreView *previewVideoPortraitTopMoreV;
  34. @property (nonatomic, strong)UIButton *landScapeToPortraitBtn;
  35. @property (nonatomic, strong)UIButton *landScapeTopMoreBtn;
  36. @property (nonatomic, strong)previewVideoLandscapeTopMoreView *previewVideoLandscapeTopMoreV;
  37. @property(nonatomic,strong) editShareView *editShareV;
  38. @property(nonatomic,assign) BOOL isPortraitType;//竖屏状态
  39. @property(nonatomic,assign) BOOL isCodeSuspendAudioType;//手动暂停播放音乐
  40. @property(nonatomic,assign) BOOL isCodeSuspendVideoType;//手动暂停播放视频
  41. @property(nonatomic,assign) BOOL didHandleRotateingType;//是否正在处理旋转
  42. @end
  43. @implementation videoPlayByAVPlayerViewController
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. [self.toolBar setHidden:YES];
  47. [self.navigationBar setHidden:YES];
  48. [self.navBarBGView setHidden:YES];
  49. //self.navBarBGView.backgroundColor = [UIColor blackColor];
  50. self.view.backgroundColor = [UIColor blackColor];
  51. _isPortraitType = YES;
  52. //[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDeviceOrientationChange) name:UIDeviceOrientationDidChangeNotification object:nil];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didInputPwdOkFun) name:didInputPWDNotification object:nil];
  54. _bgView = [[UIView alloc] init];
  55. [self.view addSubview:_bgView];
  56. [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.left.mas_equalTo(0);
  58. make.right.mas_equalTo(0);
  59. make.bottom.mas_equalTo(-safeArea);
  60. make.top.mas_equalTo(H_STATE_BAR);
  61. }];
  62. @zf_weakify(self)
  63. self.controlView.backBtnClickCallback = ^{
  64. @zf_strongify(self)
  65. [self didClickBackBtnFun];
  66. };
  67. _playerManager = [[ZFAVPlayerManager alloc] init];
  68. /// 播放器相关
  69. self.player = [[ZFPlayerController alloc] initWithPlayerManager:_playerManager containerView:_bgView];
  70. self.player.controlView = self.controlView;
  71. //self.player.allowOrentitaionRotation = NO;
  72. // self.player.orientationObserver.supportInterfaceOrientation = ZFInterfaceOrientationMaskLandscape;
  73. // [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:NO completion:nil];
  74. self.playerManager.playerPlayFailed = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, id _Nonnull error) {
  75. mainBlock(^{
  76. @zf_strongify(self)
  77. self.controlView.failBtn.hidden = YES;
  78. [[iToast makeText:NSLocalizedString(@"play_video_fail_tip",nil)] show];
  79. });
  80. };
  81. self.playerManager.playerReadyToPlay = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSURL * _Nonnull assetURL) {
  82. @zf_strongify(self)
  83. [self videoPlayerDidFun];
  84. };
  85. self.playerManager.playerDidToEnd = ^(id<ZFPlayerMediaPlayback> _Nonnull asset) {
  86. @zf_strongify(self)
  87. [self playerDidToEndFun];
  88. };
  89. //数据埋点
  90. [[netWorkManager shareInstance] DataEmbeddingPointBy:4 withEventValue:@"Video_preview"];
  91. if([DFPlayer sharedPlayer].state == DFPlayerStateBuffering
  92. ||[DFPlayer sharedPlayer].state == DFPlayerStatePlaying){
  93. _isCodeSuspendAudioType = YES;
  94. [[DFPlayer sharedPlayer] df_pause];
  95. }
  96. }
  97. - (void)viewDidAppear:(BOOL)animated
  98. {
  99. [super viewDidAppear:animated];
  100. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  101. if(!self.playerManager.assetURL){
  102. NSString *filePath = _VideoDataMode.path;
  103. NSString *urlStr = ksharedAppDelegate.NASFileByBoxService;
  104. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  105. // NSString *string = filePath;
  106. // NSString *filePathBase64 = [iTools base64UrlEncoder:string];
  107. // NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFiles/%@",urlStr,filePathBase64];
  108. NSString *showUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  109. HLog(@"video url:%@",fileUrl);
  110. //fileUrl = @"http://transfertest.armclouding.com:10010/getFile?path=/sdcard/bb.mp4";
  111. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/123.mp4";//可以播放
  112. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/movTest.mov";//可以播放
  113. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/yinwei4.mp4";//可以播放
  114. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe2.mp4";//可以播放
  115. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/fuchouzhe.m4v";//可以播放
  116. //fileUrl = @"http://file.phone.androidscloud.com:8210/document/newFile/download/1/ikIm5C0KjKNvusTF6tIH/LowLevelMultipartUpload_45050149837826456388";//可以播放
  117. //fileUrl = @"http://testprivacy.phone.armclouding.com:1801/h5/我的视频.mp4";
  118. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  119. showUrl = [showUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  120. //HLog(@"video url:%@",fileUrl);
  121. NSURL * sourceMovieURL= [NSURL URLWithString:fileUrl];
  122. self.playerManager.assetURL = sourceMovieURL;
  123. [self.controlView showTitle:_VideoDataMode.name coverURLString:showUrl fullScreenMode:ZFFullScreenModeAutomatic];
  124. [self customControlViewUIFun];
  125. }
  126. //开始生成 设备旋转 通知
  127. [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
  128. //添加 设备旋转 通知
  129. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChangeFun) name:UIDeviceOrientationDidChangeNotification object:nil];
  130. if(_isCodeSuspendVideoType){
  131. [self.player.currentPlayerManager play];
  132. }
  133. }
  134. - (void)viewWillDisappear:(BOOL)animated {
  135. [super viewWillDisappear:animated];
  136. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDarkContent];
  137. //销毁 设备旋转 通知
  138. [[NSNotificationCenter defaultCenter] removeObserver:self
  139. name:UIDeviceOrientationDidChangeNotification
  140. object:nil];
  141. //结束 设备旋转通知
  142. [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  143. if(_controlView.portraitControlView.playOrPauseBtn.selected
  144. ||_controlView.landScapeControlView.playOrPauseBtn.selected)
  145. {
  146. [self.player.currentPlayerManager pause];
  147. _isCodeSuspendVideoType = YES;
  148. }
  149. //切换到竖屏
  150. [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  151. }
  152. - (BOOL)shouldAutorotate {
  153. return NO;
  154. }
  155. /**屏幕旋转的通知回调*/
  156. - (void)orientChangeFun {
  157. UIDeviceOrientation orient = [UIDevice currentDevice].orientation;
  158. HLog(@"orientChangeFun :%d--%ld",_didHandleRotateingType,orient)
  159. if(_didHandleRotateingType){
  160. return;
  161. }
  162. KWeakSelf
  163. switch (orient) {
  164. case UIDeviceOrientationPortrait:
  165. HLog(@"竖直屏幕");
  166. if(!_isPortraitType){
  167. _didHandleRotateingType = YES;
  168. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:^{
  169. [weakSelf screenLandscapeToPortraitFun];
  170. }];
  171. }
  172. break;
  173. case UIDeviceOrientationLandscapeLeft:
  174. HLog(@"手机左转");
  175. if(_isPortraitType){
  176. _didHandleRotateingType = YES;
  177. [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:NO completion:^{
  178. [weakSelf screenPortraitToLandscapeFun];
  179. }];
  180. }
  181. break;
  182. case UIDeviceOrientationPortraitUpsideDown:
  183. // NSLog(@"手机竖直");
  184. break;
  185. case UIDeviceOrientationLandscapeRight:
  186. HLog(@"手机右转");
  187. if(_isPortraitType){
  188. _didHandleRotateingType = YES;
  189. [self.player rotateToOrientation:UIInterfaceOrientationLandscapeLeft animated:NO completion:^{
  190. [weakSelf screenPortraitToLandscapeFun];
  191. }];
  192. }
  193. break;
  194. case UIDeviceOrientationUnknown:
  195. //NSLog(@"未知");
  196. break;
  197. case UIDeviceOrientationFaceUp:
  198. //NSLog(@"手机屏幕朝上");
  199. break;
  200. case UIDeviceOrientationFaceDown:
  201. //NSLog(@"手机屏幕朝下");
  202. break;
  203. default:
  204. break;
  205. }
  206. }
  207. - (void)handleDeviceOrientationChange
  208. {
  209. [self orientChangeFun];
  210. }
  211. #pragma mark 竖屏转横屏
  212. - (void)screenPortraitToLandscapeFun{
  213. _isPortraitType = NO;
  214. _didHandleRotateingType = NO;
  215. if(_editShareV.secretShareView)
  216. {
  217. [_controlView.landScapeControlView addSubview:_editShareV.secretShareView];
  218. [_editShareV.secretShareView mas_remakeConstraints:^(MASConstraintMaker *make) {
  219. make.left.mas_equalTo(0);
  220. make.right.mas_equalTo(0);
  221. make.bottom.mas_equalTo(0);
  222. make.top.mas_equalTo(0);
  223. }];
  224. _editShareV.isPortraitType = _isPortraitType;
  225. _editShareV.secretShareView.isPortraitType = _isPortraitType;
  226. return;
  227. }
  228. if(_editShareV){
  229. _editShareV.isPortraitType = _isPortraitType;
  230. [_controlView.landScapeControlView addSubview:_editShareV];
  231. [self->_editShareV mas_remakeConstraints:^(MASConstraintMaker *make) {
  232. make.left.mas_equalTo(0);
  233. make.right.mas_equalTo(0);
  234. make.bottom.mas_equalTo(0);
  235. make.top.mas_equalTo(0);
  236. }];
  237. }
  238. }
  239. #pragma mark 横屏转竖屏
  240. - (void)screenLandscapeToPortraitFun{
  241. _isPortraitType = YES;
  242. _didHandleRotateingType = NO;
  243. if(_editShareV.secretShareView)
  244. {
  245. [self.view addSubview:_editShareV.secretShareView];
  246. [_editShareV.secretShareView mas_remakeConstraints:^(MASConstraintMaker *make) {
  247. make.left.mas_equalTo(0);
  248. make.right.mas_equalTo(0);
  249. make.bottom.mas_equalTo(0);
  250. make.top.mas_equalTo(0);
  251. }];
  252. self->_editShareV.isPortraitType = self->_isPortraitType;
  253. self->_editShareV.secretShareView.isPortraitType = self->_isPortraitType;
  254. return;
  255. }
  256. if(_editShareV){
  257. _editShareV.isPortraitType = _isPortraitType;
  258. [self.view addSubview:_editShareV];
  259. [_editShareV mas_remakeConstraints:^(MASConstraintMaker *make) {
  260. make.left.mas_equalTo(0);
  261. make.right.mas_equalTo(0);
  262. make.bottom.mas_equalTo(0);
  263. make.top.mas_equalTo(0);
  264. }];
  265. }
  266. }
  267. /// 如果不好用则copy VC中 加一下
  268. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  269. if (self.player.isFullScreen) {
  270. return UIInterfaceOrientationMaskLandscape;
  271. }
  272. return UIInterfaceOrientationMaskPortrait;
  273. }
  274. //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  275. // return UIInterfaceOrientationLandscapeRight;
  276. //}
  277. - (ZFPlayerControlView *)controlView {
  278. if (!_controlView) {
  279. _controlView = [ZFPlayerControlView new];
  280. _controlView.fastViewAnimated = YES;
  281. _controlView.effectViewShow = NO;
  282. _controlView.prepareShowLoading = YES;
  283. //_controlView.showCustomStatusBar = YES;
  284. }
  285. return _controlView;
  286. }
  287. #pragma mark reset controlView UI
  288. - (void)customControlViewUIFun
  289. {
  290. //竖屏
  291. _controlView.portraitControlView.fullScreenBtn.hidden = YES;
  292. //totalTimeLabel slider
  293. //隐藏 缓存条
  294. // _controlView.bottomPgrogress.hidden = YES;
  295. // _controlView.fastProgressView.hidden = YES;
  296. UILabel *titleLab = _controlView.portraitControlView.titleLabel;
  297. titleLab.textAlignment = NSTextAlignmentCenter;
  298. titleLab.lineBreakMode = NSLineBreakByTruncatingMiddle;
  299. CGRect titleLabFrame = titleLab.frame;
  300. HLog(@"%f %f %f %f",titleLabFrame.origin.x,titleLabFrame.origin.y,titleLabFrame.size.width,titleLabFrame.size.height);
  301. HLog(@"");
  302. [titleLab mas_remakeConstraints:^(MASConstraintMaker *make) {
  303. make.left.mas_equalTo(45);
  304. make.right.mas_equalTo(-80);
  305. make.height.mas_equalTo(titleLabFrame.size.height);
  306. make.top.mas_equalTo(titleLabFrame.origin.y);
  307. }];
  308. [_controlView.portraitControlView.topToolView addSubview:self.portraitBackBtn];
  309. [self.portraitBackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  310. make.left.mas_equalTo(15);
  311. make.width.mas_equalTo(28);
  312. make.height.mas_equalTo(28);
  313. make.top.mas_equalTo(titleLabFrame.origin.y);
  314. }];
  315. [_controlView.portraitControlView.topToolView addSubview:self.portraitTopMoreBtn];
  316. [self.portraitTopMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  317. make.right.mas_equalTo(-15);
  318. make.width.mas_equalTo(28);
  319. make.height.mas_equalTo(28);
  320. make.top.mas_equalTo(titleLabFrame.origin.y);
  321. }];
  322. [_controlView.portraitControlView.topToolView addSubview:self.portraitToLandScapeBtn];
  323. [self.portraitToLandScapeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  324. make.right.equalTo(self.portraitTopMoreBtn.mas_left).offset(-10);
  325. make.width.mas_equalTo(28);
  326. make.height.mas_equalTo(28);
  327. make.top.mas_equalTo(titleLabFrame.origin.y);
  328. }];
  329. /*************************************************************************/
  330. //横屏
  331. //_controlView.landScapeControlView.fullScreenBtn.hidden = YES;
  332. //[_controlView.landScapeControlView.backBtn addTarget:self action:@selector(didClickBackBtnFun) forControlEvents:UIControlEventTouchUpInside];
  333. UILabel *titleLabInlandScape = _controlView.landScapeControlView.titleLabel;
  334. titleLabInlandScape.textAlignment = NSTextAlignmentCenter;
  335. titleLabInlandScape.lineBreakMode = NSLineBreakByTruncatingMiddle;
  336. //CGRect titleLabFrameInlandScape = titleLabInlandScape.frame;
  337. //titleLabInlandScape.backgroundColor = [UIColor greenColor];
  338. [titleLabInlandScape mas_remakeConstraints:^(MASConstraintMaker *make) {
  339. make.left.equalTo(_controlView.landScapeControlView.backBtn.mas_right).offset(10);
  340. //make.right.mas_equalTo(-45);
  341. make.right.mas_equalTo(-25 -90);
  342. //make.height.mas_equalTo(titleLabFrameInlandScape.size.height);
  343. make.top.equalTo(_controlView.landScapeControlView.backBtn.mas_top).offset(0);
  344. make.bottom.equalTo(_controlView.landScapeControlView.backBtn.mas_bottom).offset(0);
  345. }];
  346. [_controlView.landScapeControlView.topToolView addSubview:self.landScapeTopMoreBtn];
  347. [self.landScapeTopMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  348. make.right.mas_equalTo(-15 - 20);
  349. make.width.mas_equalTo(28);
  350. make.height.mas_equalTo(28);
  351. //make.top.mas_equalTo(titleLabFrame.origin.y);
  352. make.centerY.equalTo(_controlView.landScapeControlView.backBtn.mas_centerY).offset(0);
  353. }];
  354. [_controlView.landScapeControlView.topToolView addSubview:self.landScapeToPortraitBtn];
  355. [self.landScapeToPortraitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  356. //make.right.mas_equalTo(-15);
  357. make.right.equalTo(self.landScapeTopMoreBtn.mas_left).offset(-20);
  358. make.width.mas_equalTo(28);
  359. make.height.mas_equalTo(28);
  360. //make.top.mas_equalTo(titleLabFrame.origin.y);
  361. make.centerY.equalTo(_controlView.landScapeControlView.backBtn.mas_centerY).offset(0);
  362. }];
  363. }
  364. - (UIButton *)portraitBackBtn {
  365. if (!_portraitBackBtn) {
  366. _portraitBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  367. [_portraitBackBtn setImage:ZFPlayer_Image(@"ZFPlayer_back_full") forState:UIControlStateNormal];
  368. [_portraitBackBtn addTarget:self action:@selector(didClickBackBtnFun) forControlEvents:UIControlEventTouchUpInside];
  369. }
  370. return _portraitBackBtn;
  371. }
  372. - (UIButton *)portraitToLandScapeBtn {
  373. if (!_portraitToLandScapeBtn) {
  374. _portraitToLandScapeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  375. [_portraitToLandScapeBtn setImage:[UIImage imageNamed:@"portraitFullScreen_icon"] forState:UIControlStateNormal];
  376. [_portraitToLandScapeBtn addTarget:self action:@selector(portraitOrLandScapeFun:) forControlEvents:UIControlEventTouchUpInside];
  377. //_portraitToLandScapeBtn.backgroundColor = [UIColor greenColor];
  378. }
  379. return _portraitToLandScapeBtn;
  380. }
  381. - (UIButton*)portraitTopMoreBtn{
  382. if (!_portraitTopMoreBtn) {
  383. _portraitTopMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  384. [_portraitTopMoreBtn setImage:[UIImage imageNamed:@"nas_preview_more_white"] forState:UIControlStateNormal];
  385. [_portraitTopMoreBtn addTarget:self action:@selector(didClickMoreButFun:) forControlEvents:UIControlEventTouchUpInside];
  386. //_portraitTopMoreBtn.backgroundColor = [UIColor greenColor];
  387. }
  388. return _portraitTopMoreBtn;
  389. }
  390. - (UIButton *)landScapeToPortraitBtn {
  391. if (!_landScapeToPortraitBtn) {
  392. _landScapeToPortraitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  393. [_landScapeToPortraitBtn setImage:[UIImage imageNamed:@"landScapeToPortrait_icon"] forState:UIControlStateNormal];
  394. [_landScapeToPortraitBtn addTarget:self action:@selector(portraitOrLandScapeFun:) forControlEvents:UIControlEventTouchUpInside];
  395. //_portraitToLandScapeBtn.backgroundColor = [UIColor greenColor];
  396. }
  397. return _landScapeToPortraitBtn;
  398. }
  399. - (UIButton*)landScapeTopMoreBtn{
  400. if (!_landScapeTopMoreBtn) {
  401. _landScapeTopMoreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  402. [_landScapeTopMoreBtn setImage:[UIImage imageNamed:@"nas_preview_more_white"] forState:UIControlStateNormal];
  403. [_landScapeTopMoreBtn addTarget:self action:@selector(didClickMoreButFun:) forControlEvents:UIControlEventTouchUpInside];
  404. //_portraitTopMoreBtn.backgroundColor = [UIColor greenColor];
  405. }
  406. return _landScapeTopMoreBtn;
  407. }
  408. #pragma mark 点击返回键
  409. - (void)didClickBackBtnFun
  410. {
  411. [self.player stop];
  412. //_didClickBackType = YES;
  413. if(_isCodeSuspendAudioType){
  414. [[DFPlayer sharedPlayer] df_play];
  415. }
  416. [self.navigationController popViewControllerAnimated:YES];
  417. }
  418. #pragma mark 横竖屏切换
  419. - (void)portraitOrLandScapeFun:(UIButton*)but
  420. {
  421. if(but ==_portraitToLandScapeBtn){
  422. //[self.player enterFullScreen:YES animated:YES];;
  423. [self.player rotateToOrientation:UIInterfaceOrientationLandscapeRight animated:YES completion:nil];
  424. }
  425. else{
  426. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:nil];
  427. }
  428. }
  429. #pragma mark 点击顶部更多 获取 分享 下载 更多
  430. - (void)didClickMoreButFun:(UIButton*)but
  431. {
  432. if(but ==_portraitTopMoreBtn){
  433. _previewVideoPortraitTopMoreV = [[previewVideoPortraitTopMoreView alloc] init];
  434. [self.view addSubview:_previewVideoPortraitTopMoreV];
  435. [_previewVideoPortraitTopMoreV mas_makeConstraints:^(MASConstraintMaker *make) {
  436. make.left.mas_equalTo(0);
  437. make.right.mas_equalTo(0);
  438. make.bottom.mas_equalTo(0);
  439. make.top.mas_equalTo(0);
  440. }];
  441. KWeakSelf
  442. _previewVideoPortraitTopMoreV.didClickButtonFun = ^(NSInteger tag) {
  443. if(tag == 10){
  444. [weakSelf gotoShareViewFun:NO];
  445. }
  446. else if (tag == 11){
  447. [weakSelf gotoDownLoadFileFun:NO];
  448. }
  449. else if (tag == 12){
  450. [weakSelf showDeleteAlearViewFun];
  451. }
  452. };
  453. }
  454. else{
  455. _previewVideoLandscapeTopMoreV = [[previewVideoLandscapeTopMoreView alloc] init];
  456. [_controlView.landScapeControlView addSubview:_previewVideoLandscapeTopMoreV];
  457. [_previewVideoLandscapeTopMoreV mas_makeConstraints:^(MASConstraintMaker *make) {
  458. make.left.mas_equalTo(0);
  459. make.right.mas_equalTo(0);
  460. make.bottom.mas_equalTo(0);
  461. make.top.mas_equalTo(0);
  462. }];
  463. KWeakSelf
  464. _previewVideoLandscapeTopMoreV.didClickButtonFun = ^(NSInteger tag) {
  465. if(tag == 10){
  466. [weakSelf gotoShareViewFun:YES];
  467. }
  468. else if (tag == 11){
  469. [weakSelf gotoDownLoadFileFun:YES];
  470. }
  471. else if (tag == 12){
  472. [weakSelf didClickDeleteInLandscapeFun];
  473. }
  474. };
  475. }
  476. }
  477. #pragma mark 横屏点击删除
  478. - (void)didClickDeleteInLandscapeFun
  479. {
  480. //横屏的删除 要转竖屏
  481. // [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:^{
  482. // [self screenLandscapeToPortraitFun];
  483. // [self showDeleteAlearViewFun];
  484. // }];
  485. //修复iOS15 bug
  486. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:^{
  487. }];
  488. KWeakSelf
  489. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  490. [weakSelf screenLandscapeToPortraitFun];
  491. [weakSelf showDeleteAlearViewFun];
  492. });
  493. }
  494. #pragma mark 视频可以播放 加入最近文件
  495. - (void)videoPlayerDidFun{
  496. NASFileAndFolderDataModel *dataModel = _VideoDataMode;
  497. lastFileModel *lastFileMod = [lastFileModel new];
  498. lastFileMod.path = dataModel.path;
  499. lastFileMod.name = dataModel.name;
  500. lastFileMod.time = dataModel.time;
  501. lastFileMod.size = dataModel.size;
  502. lastFileMod.duration = dataModel.duration;
  503. lastFileMod.type = @"video";
  504. lastFileMod.lastPreTime = [iTools getNowTimeStamp];
  505. [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
  506. }
  507. #pragma mark 用户点击分享
  508. - (void)gotoShareViewFun:(BOOL)isLandscapeType
  509. {
  510. if(!_VideoDataMode){
  511. return;
  512. }
  513. if(isLandscapeType){//强制竖屏
  514. //修复iOS15 bug
  515. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:NO completion:^{
  516. }];
  517. isLandscapeType = NO;
  518. }
  519. _editShareV = [[editShareView alloc] init];
  520. _editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[_VideoDataMode]];
  521. _editShareV.shareFileType = @"3";
  522. if(isLandscapeType){
  523. _editShareV.isPortraitType = NO;
  524. [_controlView.landScapeControlView addSubview:_editShareV];
  525. }
  526. else{
  527. _editShareV.isPortraitType = YES;
  528. [self.view addSubview:_editShareV];
  529. }
  530. [_editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  531. make.left.mas_equalTo(0);
  532. make.right.mas_equalTo(0);
  533. make.bottom.mas_equalTo(0);
  534. make.top.mas_equalTo(0);
  535. }];
  536. KWeakSelf
  537. _editShareV.didClickCloseFun = ^{
  538. [weakSelf clearShareAboutViewFun];
  539. };
  540. }
  541. #pragma mark 清理分享相关页面
  542. - (void)clearShareAboutViewFun
  543. {
  544. if(_editShareV.secretShareView){
  545. _editShareV.secretShareView = nil;
  546. }
  547. _editShareV = nil;
  548. }
  549. #pragma mark 删除视频
  550. - (void)showDeleteAlearViewFun
  551. {
  552. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  553. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  554. KWeakSelf
  555. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  556. msg:tipStr
  557. imageStr:nil
  558. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  559. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  560. didClickOk:^{
  561. [weakSelf delFileListFun];
  562. } didClickCancel:^{
  563. }];
  564. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  565. [self presentViewController:curAlretVC animated:YES completion:^{
  566. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  567. }];
  568. }
  569. #pragma mark 删除文件数据
  570. - (void)delFileListFun
  571. {
  572. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  573. if(_VideoDataMode){
  574. NSArray *pathArr = @[_VideoDataMode.path];
  575. [paraDict setValue:pathArr forKey:@"path"];
  576. }
  577. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  578. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  579. KWeakSelf //@"delFile"
  580. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  581. [weakSelf removeNewIndicator];
  582. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  583. if(model && model.status == 0){
  584. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  585. [weakSelf didDeleteSucFun:self->_VideoDataMode.path];
  586. }
  587. else{
  588. }
  589. } failure:^(NSError * _Nonnull error) {
  590. [weakSelf removeNewIndicator];
  591. }];
  592. //数据埋点
  593. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_delete"];
  594. }
  595. #pragma mark 删除成功
  596. - (void)didDeleteSucFun:(NSString*)path
  597. {
  598. //1.删除最近文件数据
  599. [[lastFileManager shareManager] deleteFileInfoWithUrl:path];
  600. if(_didNeedDeleteFile){
  601. _didNeedDeleteFile(path);
  602. }
  603. [self.navigationController popViewControllerAnimated:YES];
  604. }
  605. #pragma mark 去下载文件
  606. - (void)gotoDownLoadFileFun:(BOOL)isLandscapeType
  607. {
  608. if(_VideoDataMode){
  609. if(isLandscapeType){
  610. //切换到竖屏
  611. //[self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  612. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:nil];
  613. }
  614. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  615. fileModel.fileType = _VideoDataMode.type;
  616. fileModel.path = _VideoDataMode.path;
  617. fileModel.name = _VideoDataMode.name;
  618. fileModel.length = _VideoDataMode.size;
  619. NSMutableArray *arr = [NSMutableArray new];
  620. [arr addObject:fileModel];
  621. //切换到竖屏
  622. [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  623. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  624. [self.navigationController pushViewController:vc animated:YES];
  625. vc.isDownloadingType = YES;
  626. [vc gotoDownloadFile:arr];
  627. }
  628. }
  629. #pragma mark 输入完密码
  630. - (void)didInputPwdOkFun
  631. {
  632. if(ksharedAppDelegate.DeviceThirdIdMod.data.isPrivacyMode){
  633. if(self.player.pauseByEvent){//隐私模式 是
  634. self.player.pauseByEvent = NO;
  635. }
  636. }
  637. }
  638. #pragma mark 播放完成
  639. - (void)playerDidToEndFun
  640. {
  641. KWeakSelf
  642. [self.player seekToTime:0 completionHandler:^(BOOL finished) {
  643. [weakSelf.playerManager pause];
  644. [weakSelf.controlView.portraitControlView playBtnSelectedState:NO];
  645. [weakSelf.controlView.landScapeControlView playBtnSelectedState:NO];
  646. }];
  647. }
  648. @end