videoPlayByAVPlayerViewController.m 27 KB

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