From 4c1abca185a5727da6fb314a0cb4cd44bfe1b3bf Mon Sep 17 00:00:00 2001 From: Davin <591807572@qq.com> Date: 星期五, 07 六月 2024 17:48:47 +0800 Subject: [PATCH] feature appkey修改 --- EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m | 142 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 132 insertions(+), 10 deletions(-) diff --git a/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m b/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m index 34cb569..836d0d4 100644 --- a/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m +++ b/EZSDK/EZSDK/EZ/UIViewControllers/EZPlaybackViewController.m @@ -25,6 +25,9 @@ #import "Toast+UIView.h" #import "EZCustomTableView.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> @@ -333,7 +336,7 @@ cell.isSelectedDevice = _isSelectedDevice; cell.delegate = self; //2021-07-21 闅愯棌涓嬭浇鎸夐挳 - [cell.downloadBtn setHidden:YES]; + [cell.downloadBtn setHidden:NO]; if(_isSelectedDevice) { @@ -421,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 { @@ -454,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: @@ -500,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]; @@ -512,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: @@ -553,6 +612,69 @@ } } +#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 - (void)player:(EZPlayer *)player didPlayFailed:(NSError *)error -- Gitblit v1.8.0