From b4e1288a9b63eb820e9c9489c56aac4bf6b31067 Mon Sep 17 00:00:00 2001 From: Davin <591807572@qq.com> Date: 星期三, 18 十二月 2024 14:34:16 +0800 Subject: [PATCH] feature 图片资源更新 --- EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m | 253 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 229 insertions(+), 24 deletions(-) diff --git a/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m b/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m index d7f2e5f..836d0d4 100644 --- a/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m +++ b/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m @@ -10,27 +10,31 @@ #import "UIViewController+EZBackPop.h" #import "DDCollectionViewFlowLayout.h" #import "MJRefresh.h" -#import "EZRecordDownloader.h" -#import "EZDeviceRecordDownloadTask.h" -#import "EZCloudRecordDownloadTask.h" +#import <EZOpenSDKFramework/EZRecordDownloader.h> +#import <EZOpenSDKFramework/EZDeviceRecordDownloadTask.h> +#import <EZOpenSDKFramework/EZCloudRecordDownloadTask.h> #import "EZRecordCell.h" #import "DDKit.h" -#import "EZCloudRecordFile.h" -#import "EZDeviceRecordFile.h" -#import "EZPlayer.h" +#import <EZOpenSDKFramework/EZCloudRecordFile.h> +#import <EZOpenSDKFramework/EZDeviceRecordFile.h> +#import <EZOpenSDKFramework/EZPlayer.h> #import "HIKLoadView.h" #import "Masonry.h" -#import "EZCameraInfo.h" +#import <EZOpenSDKFramework/EZCameraInfo.h> #import "MBProgressHUD.h" #import "Toast+UIView.h" #import "EZCustomTableView.h" -#import "EZStreamPlayer.h" +#import <EZOpenSDKFramework/EZStreamPlayer.h> +#import <Photos/Photos.h> +#import "FCFileManager.h" +#import <EZOpenSDKFramework/EZVideoTransformer.h> @interface EZPlaybackViewController ()<DDCollectionViewDelegateFlowLayout, UICollectionViewDataSource,EZPlayerDelegate, UIAlertViewDelegate, EZRecordCellDelegate, EZCustomTableViewDelegate,EZStreamPlayerDelegate> { BOOL _isOpenSound; BOOL _isPlaying; + BOOL _landscape; // 鏄惁鏃嬭浆 NSTimeInterval _playSeconds; //鎾斁绉掓暟 NSTimeInterval _duringSeconds; //褰曞儚鏃堕暱 @@ -57,6 +61,7 @@ @property (nonatomic, strong) HIKLoadView *loadingView; @property (nonatomic) BOOL isSelectedDevice; @property (nonatomic, weak) IBOutlet UIView *playerView; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *playViewWHScale; @property (nonatomic, weak) IBOutlet UILabel *largeTitleLabel; @property (nonatomic, weak) IBOutlet UIDatePicker *datePicker; @property (nonatomic, weak) IBOutlet UITextField *dateTextField; @@ -115,6 +120,7 @@ self.isAutorotate = YES; self.largeTitleLabel.text = self.deviceInfo.deviceName; self.largeTitleLabel.hidden = YES; + _landscape = NO; if(!_records) _records = [NSMutableArray new]; @@ -191,8 +197,9 @@ cloudRateStr = @[@"x1",@"x4",@"x8",@"x16",@"x32"]; sdCardRateStr = @[@"x1",@"x4",@"x8",@"x16"]; - //2021-07-21 闅愯棌streamPlayBtn + //2021-07-21 闅愯棌streamPlayBtn鍜宺ateBtn [self.streamPlayBtn setHidden:YES]; + [self.rateBtn setHidden:YES]; } @@ -226,7 +233,17 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations { - return UIInterfaceOrientationMaskAllButUpsideDown; + if (@available(iOS 16.0, *)) { + if (_landscape) { + //妯睆 + return UIInterfaceOrientationMaskLandscape; + } else { + //绔栧睆 + return UIInterfaceOrientationMaskPortrait; + } + } else { + return UIInterfaceOrientationMaskAllButUpsideDown; + } } - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation @@ -241,6 +258,13 @@ self.largeButton.hidden = NO; self.voiceButton.hidden = NO; self.playButton.hidden = NO; + [self.playerView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [NSLayoutConstraint deactivateConstraints:@[self.playViewWHScale]]; + self.playViewWHScale = [NSLayoutConstraint constraintWithItem:self.playerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeHeight multiplier:16/9. constant:0]; + [NSLayoutConstraint activateConstraints:@[self.playViewWHScale]]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.playerView layoutIfNeeded]; + }); if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { @@ -253,6 +277,18 @@ self.playbackList.hidden = YES; self.largeBackButton.hidden = NO; self.navigationController.navigationBarHidden = YES; + + CGFloat tureScreenW = HDLEZ_APP_SCREEN_WIDTH > HDLEZ_APP_SCREEN_HEIGHT ? HDLEZ_APP_SCREEN_HEIGHT : HDLEZ_APP_SCREEN_WIDTH; + CGFloat tureScreenH = HDLEZ_APP_SCREEN_WIDTH < HDLEZ_APP_SCREEN_HEIGHT ? HDLEZ_APP_SCREEN_HEIGHT : HDLEZ_APP_SCREEN_WIDTH; + + + [self.playerView setTranslatesAutoresizingMaskIntoConstraints:NO]; + [NSLayoutConstraint deactivateConstraints:@[self.playViewWHScale]]; + self.playViewWHScale = [NSLayoutConstraint constraintWithItem:self.playerView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.playerView attribute:NSLayoutAttributeHeight multiplier:tureScreenH/(tureScreenW) constant:0]; + [NSLayoutConstraint activateConstraints:@[self.playViewWHScale]]; + dispatch_async(dispatch_get_main_queue(), ^{ + [self.playerView layoutIfNeeded]; + }); } } @@ -300,7 +336,7 @@ cell.isSelectedDevice = _isSelectedDevice; cell.delegate = self; //2021-07-21 闅愯棌涓嬭浇鎸夐挳 - [cell.downloadBtn setHidden:YES]; + [cell.downloadBtn setHidden:NO]; if(_isSelectedDevice) { @@ -388,9 +424,16 @@ EZDeviceRecordFile *deviceFile = (EZDeviceRecordFile *)recordFile; - NSString *path = [NSString stringWithFormat:@"%@/ezopensdk/DeviceRecord/%@.ps",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject], [dateformatter stringFromDate:deviceFile.startTime]]; + NSString *path = [NSString stringWithFormat:@"%@/ezopensdk/DeviceRecord/%@.ps",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], [dateformatter stringFromDate:deviceFile.startTime]]; NSLog(@"path: %@ ", path); - [self startDeviceRecordDownload:path deviceFile:deviceFile]; + __weak __typeof(self)weakSelf = self; + [self authPhotoLibraries:^(BOOL isAblity) { + if (isAblity) { + [weakSelf startDeviceRecordDownload:path deviceFile:deviceFile]; + } else { + [weakSelf guideUserOpenAuth]; + } + }]; } else { @@ -421,10 +464,17 @@ NSLog(@"statuCode:%ld", (long)statusCode); switch (statusCode) { - case EZRecordDownloaderStatusFinish: - - [self.navigationController.view makeToast:[NSString stringWithFormat:@"SDD Task:%lu-涓嬭浇鎴愬姛", (unsigned long)strongTask.taskID]]; - + case EZRecordDownloaderStatusFinish:{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSLog(@"#########寮�濮嬩繚瀛樿棰戯紒锛侊紒锛�%@", path); + + NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init]; + dateformatter.dateFormat = @"yyyyMMddHHmmss"; + + NSString *mp4Path = [NSString stringWithFormat:@"%@/ezopensdk/DeviceRecord/%@.mp4", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], [dateformatter stringFromDate:deviceFile.startTime]]; + [self videoFormatConvertAndSave2Album:path mp4Path:mp4Path]; + }); + } break; case EZRecordDownloaderStatusMoreToken: @@ -467,6 +517,40 @@ }]; } +/** 濡傛灉闇�瑕佹妸鍥炴斁瑙嗛淇濆瓨鍒扮浉鍐岋紝涓�瀹氳鍏堟妸.ps鏂囦欢杞垚.mp4鏂囦欢 + 娉ㄦ剰锛氫笅杞藉綍鍍忚繃绋嬩腑鍥犱负缃戠粶鍘熷洜瀵艰嚧.ps鏂囦欢鏈笅杞藉畬锛屼篃鍙互璋冪敤姝ゆ柟娉曞皢宸蹭笅杞界殑褰曞儚鐗囨瑙g爜鎴�.mp4鏂囦欢銆� + */ +- (void)videoFormatConvertAndSave2Album:(NSString *)psPath mp4Path:(NSString *)mp4Path { + [FCFileManager createFileAtPath:mp4Path overwrite:YES]; + __weak typeof(self) weakSelf = self; + [EZVideoTransformer videoTransFormerPSPath:psPath toPath:mp4Path type:EZVideoTransformerTypeMP4 withKey:_verifyCode succBlock:^{ + NSLog(@"杞崲鎴愬姛"); + // 灏�.mp4鏂囦欢淇濆瓨鍒扮浉鍐� + PHPhotoLibrary *photoLibrary = [PHPhotoLibrary sharedPhotoLibrary]; + [photoLibrary performChanges:^{ + [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:[NSURL fileURLWithPath:mp4Path]]; + } completionHandler:^(BOOL success, NSError * _Nullable error) { + if (success) { + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf.navigationController.view makeToast:HDLEZLocallizedString(@"device_save_gallery")]; + }); + NSLog(@"########淇濆瓨鎴愬姛锛侊紒锛�"); + // 涓嬭浇瀹屾垚鍚庡垹闄�.ps鍜�.mp4鏂囦欢 + [FCFileManager removeItemAtPath:psPath]; + [FCFileManager removeItemAtPath:mp4Path]; + } else { + dispatch_async(dispatch_get_main_queue(), ^{ + [weakSelf.navigationController.view makeToast:HDLEZLocallizedString(@"device_save_gallery_failure")]; + }); + } + }]; + } processBlock:^(int rate) { + // 杞崲杩涘害 + } failBlock:^(int errCode) { + NSLog(@"杞崲澶辫触"); + }]; +} + - (void) startCloudRecordDownload:(NSString*)path cloudFile:(EZCloudRecordFile *)cloudFile { EZCloudRecordDownloadTask *task = [[EZCloudRecordDownloadTask alloc] initTaskWithID:_selectedIndexPath.row cloudRecordFile:cloudFile verifyCode:self.verifyCode savePath:path]; @@ -479,9 +563,17 @@ NSLog(@"statuCode:%ld", (long)statusCode); switch (statusCode) { - case EZRecordDownloaderStatusFinish: - - [self.navigationController.view makeToast:[NSString stringWithFormat:@"CD Task:%lu-涓嬭浇鎴愬姛", (unsigned long)strongTask.taskID]]; + case EZRecordDownloaderStatusFinish: { + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSLog(@"#########寮�濮嬩繚瀛樿棰戯紒锛侊紒锛�%@", path); + + NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init]; + dateformatter.dateFormat = @"yyyyMMddHHmmss"; + + NSString *mp4Path = [NSString stringWithFormat:@"%@/ezopensdk/DeviceRecord/%@.mp4", [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], [dateformatter stringFromDate:cloudFile.startTime]]; + [self videoFormatConvertAndSave2Album:path mp4Path:mp4Path]; + }); + } break; case EZRecordDownloaderStatusMoreToken: @@ -518,6 +610,69 @@ [self.navigationController.view makeToast:[NSString stringWithFormat:@"CD Task:%lu-浠诲姟宸插湪涓嬭浇涓�", (unsigned long)task.taskID]]; } } +} + +#pragma mark 瑙嗛淇濆瓨瀹屾瘯鐨勫洖璋� +- (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (error) { + [self.navigationController.view makeToast:HDLEZLocallizedString(@"device_save_gallery_failure")]; + NSLog(@"淇濆瓨瑙嗛杩囩▼涓彂鐢熼敊璇紝閿欒淇℃伅:%@",error.localizedDescription); + NSLog(@"淇濆瓨瑙嗛杩囩▼涓彂鐢熼敊璇紝閿欒淇℃伅:%@",error); + }else{ + [self.navigationController.view makeToast:HDLEZLocallizedString(@"device_save_gallery")]; + NSLog(@"瑙嗛淇濆瓨鎴愬姛."); + } + }); +} + +/*璁块棶鐩稿唽鏉冮檺 + */ +-(void)authPhotoLibraries:(void(^)(BOOL isAblity))result { + PHAuthorizationStatus author =[PHPhotoLibrary authorizationStatus]; + if (author == PHAuthorizationStatusRestricted || author ==PHAuthorizationStatusDenied){ + if (result) { + result(NO); + } + } else if (author == PHAuthorizationStatusNotDetermined) { // 棣栨鎺堟潈 + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); + dispatch_async(queue, ^{ + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) { + if (status != PHAuthorizationStatusAuthorized) { + if (result) { + result(NO); + } + } else { + if (result) { + result(YES); + } + } + }]; + }); + } else { + if (result) { + result(YES); + } + } +} + +/*寮曞鐢ㄦ埛鎺堟潈鑾峰彇鍥剧墖 + */ +- (void)guideUserOpenAuth{ + UIAlertController *alertC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"hdl_ez_download_tip", @"娓╅Θ鎻愮ず") message:NSLocalizedString(@"hdl_ez_download_auth", @"璇锋墦寮�璁块棶鏉冮檺") preferredStyle:(UIAlertControllerStyleAlert)]; + UIAlertAction *alertA = [UIAlertAction actionWithTitle:NSLocalizedString(@"hdl_ez_download_cancle", @"鍙栨秷") style:(UIAlertActionStyleDefault) handler:nil]; + UIAlertAction *act = [UIAlertAction actionWithTitle:NSLocalizedString(@"hdl_ez_download_toSet", @"鍘昏缃�") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + // 寮曞鐢ㄦ埛璁剧疆 + NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; + + if ([[UIApplication sharedApplication] canOpenURL:url]) { + + [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; + } + }]; + [alertC addAction:alertA]; + [alertC addAction:act]; + [self presentViewController:alertC animated:YES completion:nil]; } #pragma mark - PlayerDelegate Methods @@ -756,14 +911,60 @@ - (IBAction)large:(id)sender { - NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; - [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; +// NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; +// [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + if (_landscape == YES) { + [self largeBack:self.largeBackButton]; + return; + } + _landscape = YES; + if (@available(iOS 16.0, *)) { + if (self.navigationController) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations]; + }); + } else { + dispatch_async(dispatch_get_main_queue(), ^{ + [self setNeedsUpdateOfSupportedInterfaceOrientations]; + }); + } + NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; + UIWindowScene *ws = (UIWindowScene *)array.firstObject; + UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init]; + geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskLandscape; + [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { + NSLog(@"iOS 16 Error: %@",error); + }]; + } else { + NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; + [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + } } - (IBAction)largeBack:(id)sender { - NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; - [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + _landscape = NO; + if (@available(iOS 16.0, *)) { + if (self.navigationController) { + dispatch_async(dispatch_get_main_queue(), ^{ + [self.navigationController setNeedsUpdateOfSupportedInterfaceOrientations]; + }); + } else { + dispatch_async(dispatch_get_main_queue(), ^{ + [self setNeedsUpdateOfSupportedInterfaceOrientations]; + }); + } + NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects]; + UIWindowScene *ws = (UIWindowScene *)array.firstObject; + UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init]; + geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskPortrait; + [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) { + NSLog(@"iOS 16 Error: %@",error); + }]; + } else { + NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; + [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + } } - (IBAction)voiceButtonClicked:(id)sender @@ -1159,4 +1360,8 @@ } } +- (BOOL)prefersHomeIndicatorAutoHidden { + return YES; +} + @end -- Gitblit v1.8.0