videoPlayByAVPlayerViewController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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(@"hxd 333333 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. HLog(@"hxd 333333")
  211. [self orientChangeFun];
  212. }
  213. #pragma mark 竖屏转横屏
  214. - (void)screenPortraitToLandscapeFun{
  215. _isPortraitType = NO;
  216. if(_editShareV.secretShareView)
  217. {
  218. [_controlView.landScapeControlView addSubview:_editShareV.secretShareView];
  219. [_editShareV.secretShareView mas_remakeConstraints:^(MASConstraintMaker *make) {
  220. make.left.mas_equalTo(0);
  221. make.right.mas_equalTo(0);
  222. make.bottom.mas_equalTo(0);
  223. make.top.mas_equalTo(0);
  224. }];
  225. _editShareV.isPortraitType = _isPortraitType;
  226. _editShareV.secretShareView.isPortraitType = _isPortraitType;
  227. return;
  228. }
  229. if(_editShareV){
  230. _editShareV.isPortraitType = _isPortraitType;
  231. [_controlView.landScapeControlView addSubview:_editShareV];
  232. [self->_editShareV mas_remakeConstraints:^(MASConstraintMaker *make) {
  233. make.left.mas_equalTo(0);
  234. make.right.mas_equalTo(0);
  235. make.bottom.mas_equalTo(0);
  236. make.top.mas_equalTo(0);
  237. }];
  238. }
  239. }
  240. #pragma mark 横屏转竖屏
  241. - (void)screenLandscapeToPortraitFun{
  242. _isPortraitType = YES;
  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(-45);
  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. }
  486. #pragma mark 视频可以播放 加入最近文件
  487. - (void)videoPlayerDidFun{
  488. NASFileAndFolderDataModel *dataModel = _VideoDataMode;
  489. lastFileModel *lastFileMod = [lastFileModel new];
  490. lastFileMod.path = dataModel.path;
  491. lastFileMod.name = dataModel.name;
  492. lastFileMod.time = dataModel.time;
  493. lastFileMod.size = dataModel.size;
  494. lastFileMod.duration = dataModel.duration;
  495. lastFileMod.type = @"video";
  496. lastFileMod.lastPreTime = [iTools getNowTimeStamp];
  497. [[lastFileManager shareManager] saveFileInfoWith:lastFileMod with:dataModel.path];
  498. }
  499. #pragma mark 用户点击分享
  500. - (void)gotoShareViewFun:(BOOL)isLandscapeType
  501. {
  502. if(!_VideoDataMode){
  503. return;
  504. }
  505. _editShareV = [[editShareView alloc] init];
  506. _editShareV.didSelectListArr = [NSMutableArray arrayWithArray:@[_VideoDataMode]];
  507. _editShareV.shareFileType = @"3";
  508. if(isLandscapeType){
  509. _editShareV.isPortraitType = NO;
  510. [_controlView.landScapeControlView addSubview:_editShareV];
  511. }
  512. else{
  513. _editShareV.isPortraitType = YES;
  514. [self.view addSubview:_editShareV];
  515. }
  516. [_editShareV mas_makeConstraints:^(MASConstraintMaker *make) {
  517. make.left.mas_equalTo(0);
  518. make.right.mas_equalTo(0);
  519. make.bottom.mas_equalTo(0);
  520. make.top.mas_equalTo(0);
  521. }];
  522. }
  523. #pragma mark 删除图片
  524. - (void)showDeleteAlearViewFun
  525. {
  526. NSString *titleStr = NSLocalizedString(@"delete_file_title_msg",nil);
  527. NSString *tipStr = NSLocalizedString(@"delete_file_tip_msg",nil);
  528. KWeakSelf
  529. ComontAlretViewController *curAlretVC= [[ComontAlretViewController alloc] initWithTiTle:titleStr
  530. msg:tipStr
  531. imageStr:nil
  532. cancelTitle:NSLocalizedString(@"other_cancel",nil)
  533. okTitle:NSLocalizedString(@"other_confirm",nil) isOkBtnHighlight:YES
  534. didClickOk:^{
  535. [weakSelf delFileListFun];
  536. } didClickCancel:^{
  537. }];
  538. curAlretVC.modalPresentationStyle = UIModalPresentationCustom;
  539. [self presentViewController:curAlretVC animated:YES completion:^{
  540. curAlretVC.view.superview.backgroundColor = [UIColor clearColor];
  541. }];
  542. }
  543. #pragma mark 删除文件数据
  544. - (void)delFileListFun
  545. {
  546. NSMutableDictionary*paraDict = [NSMutableDictionary new];
  547. if(_VideoDataMode){
  548. NSArray *pathArr = @[_VideoDataMode.path];
  549. [paraDict setValue:pathArr forKey:@"path"];
  550. }
  551. [self showNewIndicatorWithCanBack:YES canTouch:NO];
  552. //NSString*code = [[NSString alloc] initWithFormat:@"delFile?path=%@",paraDict[@"path"]]; //delFile?path=[/storage/emulated/0/Download/IMG_6464.HEIC]
  553. KWeakSelf //@"delFile"
  554. [[netWorkManager shareInstance] cloudPhonePostCallBackCode:@"delFile" Parameters:paraDict success:^(id _Nonnull responseObject) {
  555. [weakSelf removeNewIndicator];
  556. SuperModel *model = [[SuperModel alloc] initWithDictionary:responseObject error:nil];
  557. if(model && model.status == 0){
  558. [[iToast makeText:NSLocalizedString(@"delete_file_suc_msg",nil)] show];
  559. [weakSelf didDeleteSucFun:self->_VideoDataMode.path];
  560. }
  561. else{
  562. }
  563. } failure:^(NSError * _Nonnull error) {
  564. [weakSelf removeNewIndicator];
  565. }];
  566. //数据埋点
  567. [[netWorkManager shareInstance] DataEmbeddingPointBy:3 withEventValue:@"Video_delete"];
  568. }
  569. #pragma mark 删除成功
  570. - (void)didDeleteSucFun:(NSString*)path
  571. {
  572. //1.删除最近文件数据
  573. [[lastFileManager shareManager] deleteFileInfoWithUrl:path];
  574. if(_didNeedToRegetDataFun){
  575. _didNeedToRegetDataFun();
  576. }
  577. [self.navigationController popViewControllerAnimated:YES];
  578. }
  579. #pragma mark 去下载文件
  580. - (void)gotoDownLoadFileFun:(BOOL)isLandscapeType
  581. {
  582. if(_VideoDataMode){
  583. if(isLandscapeType){
  584. //切换到竖屏
  585. //[self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  586. [self.player rotateToOrientation:UIInterfaceOrientationPortrait animated:YES completion:nil];
  587. }
  588. couldPhoneFileModel* fileModel = [couldPhoneFileModel new];
  589. fileModel.fileType = _VideoDataMode.type;
  590. fileModel.path = _VideoDataMode.path;
  591. fileModel.name = _VideoDataMode.name;
  592. fileModel.length = _VideoDataMode.size;
  593. NSMutableArray *arr = [NSMutableArray new];
  594. [arr addObject:fileModel];
  595. //切换到竖屏
  596. [self hx_rotateToInterfaceOrientation:UIInterfaceOrientationPortrait];
  597. uploadFileRecordViewController *vc = [uploadFileRecordViewController new];
  598. [self.navigationController pushViewController:vc animated:YES];
  599. vc.isDownloadingType = YES;
  600. [vc gotoDownloadFile:arr];
  601. }
  602. }
  603. @end