videoPlayByAVPlayerViewController.m 28 KB

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