From e0125feda192549f6bdfec6bb734f5b82eafd477 Mon Sep 17 00:00:00 2001 From: longitachi Date: Tue, 5 Dec 2017 16:24:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A7=86=E9=A2=91=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PhotoBrowser/ZLPhotoActionSheet.h | 2 +- PhotoBrowser/ZLPhotoManager.h | 8 ++++- PhotoBrowser/ZLPhotoManager.m | 54 ++++++++++++++++++++++++------- README.md | 2 ++ ZLPhotoBrowser.podspec | 2 +- ZLPhotoBrowser/Info.plist | 2 +- 6 files changed, 54 insertions(+), 16 deletions(-) diff --git a/PhotoBrowser/ZLPhotoActionSheet.h b/PhotoBrowser/ZLPhotoActionSheet.h index 0f5c21a7..828557b5 100644 --- a/PhotoBrowser/ZLPhotoActionSheet.h +++ b/PhotoBrowser/ZLPhotoActionSheet.h @@ -5,7 +5,7 @@ // Created by long on 15/11/25. // Copyright © 2015年 long. All rights reserved. // -//pods version 2.5.1.1 - 2017.11.15 update +//pods version 2.5.4 - 2017.12.5 update #import #import "ZLPhotoConfiguration.h" diff --git a/PhotoBrowser/ZLPhotoManager.h b/PhotoBrowser/ZLPhotoManager.h index 4bd93276..9cd0cc24 100644 --- a/PhotoBrowser/ZLPhotoManager.h +++ b/PhotoBrowser/ZLPhotoManager.h @@ -152,12 +152,18 @@ + (void)analysisEverySecondsImageForAsset:(PHAsset *)asset interval:(NSTimeInterval)interval size:(CGSize)size complete:(void (^)(AVAsset *avAsset, NSArray *images))complete; /** - 导出视频并保存到相册 + 导出编辑的片段视频并保存到相册 @param range 需要到处的视频间隔 */ + (void)exportEditVideoForAsset:(AVAsset *)asset range:(CMTimeRange)range type:(ZLExportVideoType)type complete:(void (^)(BOOL isSuc, PHAsset *asset))complete; + +/** + 导出视频 + */ ++ (void)exportVideoForAsset:(PHAsset *)asset type:(ZLExportVideoType)type complete:(void (^)(NSString *exportFilePath, NSError *error))complete; + #pragma mark - 相册、相机、麦克风权限相关 /** 是否有相册访问权限 diff --git a/PhotoBrowser/ZLPhotoManager.m b/PhotoBrowser/ZLPhotoManager.m index bb93d656..dc4b596d 100644 --- a/PhotoBrowser/ZLPhotoManager.m +++ b/PhotoBrowser/ZLPhotoManager.m @@ -712,9 +712,7 @@ + (void)requestAssetFileUrl:(PHAsset *)asset complete:(void (^)(NSString *))comp } }]; } else { - CGFloat width = MIN(kViewWidth, kMaxImageWidth); - CGSize size = CGSizeMake(width, width*asset.pixelHeight/asset.pixelWidth); - [self requestImageForAsset:asset size:size completion:^(UIImage *image, NSDictionary *info) { + [self requestOriginalImageDataForAsset:asset completion:^(NSData *data, NSDictionary *info) { if ([[info objectForKey:PHImageResultIsDegradedKey] boolValue]) return; if (complete) { NSURL *url = info[@"PHImageFileURLKey"]; @@ -785,6 +783,41 @@ + (void)analysisAVAsset:(AVAsset *)asset interval:(NSTimeInterval)interval size: } + (void)exportEditVideoForAsset:(AVAsset *)asset range:(CMTimeRange)range type:(ZLExportVideoType)type complete:(void (^)(BOOL, PHAsset *))complete +{ + [self export:asset range:range type:type complete:^(NSString *exportFilePath, NSError *error) { + if (!error) { + [self saveVideoToAblum:[NSURL URLWithString:exportFilePath] completion:^(BOOL isSuc, PHAsset *asset) { + if (complete) complete(isSuc, asset); + if (isSuc) { + NSLog(@"导出的的视频路径: %@", exportFilePath); + } else { + NSLog(@"导出视频失败"); + } + }]; + } else { + if (complete) { + complete(NO, nil); + } + } + }]; +} + ++ (void)exportVideoForAsset:(PHAsset *)asset type:(ZLExportVideoType)type complete:(void (^)(NSString *, NSError *))complete +{ + PHVideoRequestOptions* options = [[PHVideoRequestOptions alloc] init]; + options.version = PHVideoRequestOptionsVersionOriginal; + options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic; + options.networkAccessAllowed = YES; + [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) { + [self export:asset range:CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity) type:type complete:^(NSString *exportFilePath, NSError *error) { + if (complete) { + complete(exportFilePath, error); + } + }]; + }]; +} + ++ (void)export:(AVAsset *)asset range:(CMTimeRange)range type:(ZLExportVideoType)type complete:(void (^)(NSString *exportFilePath, NSError *error))complete { NSString *exportFilePath = [self getVideoExportFilePath:type]; @@ -797,7 +830,7 @@ + (void)exportEditVideoForAsset:(AVAsset *)asset range:(CMTimeRange)range type:( exportSession.timeRange = range; [exportSession exportAsynchronouslyWithCompletionHandler:^{ - + BOOL suc = NO; switch ([exportSession status]) { case AVAssetExportSessionStatusFailed: NSLog(@"Export failed: %@", [[exportSession error] localizedDescription]); @@ -808,14 +841,7 @@ + (void)exportEditVideoForAsset:(AVAsset *)asset range:(CMTimeRange)range type:( case AVAssetExportSessionStatusCompleted:{ NSLog(@"Export completed"); - [self saveVideoToAblum:exportFileUrl completion:^(BOOL isSuc, PHAsset *asset) { - if (complete) complete(isSuc, asset); - if (isSuc) { - NSLog(@"导出的的视频路径: %@", exportFilePath); - } else { - NSLog(@"导出视频失败"); - } - }]; + suc = YES; } break; @@ -823,6 +849,10 @@ + (void)exportEditVideoForAsset:(AVAsset *)asset range:(CMTimeRange)range type:( NSLog(@"Export other"); break; } + + if (complete) { + complete(suc?exportFilePath:nil, suc?nil:exportSession.error); + } }]; } diff --git a/README.md b/README.md index 3e89a623..e5a136c3 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ - [x] 自定义升序降序排列 - [x] 支持点击拍照及长按录制视频 (仿微信) - [x] 开发者可自定义资源图片 +- [x] 支持视频导出 ### Feature @@ -44,6 +45,7 @@ ### 更新日志 ``` +● 2.5.4: 新增视频导出功能; 新增获取图片路径api; 优化自定义相机,当相机消失后恢复其他音乐软件的播放; ● 2.5.3: 拍摄视频及编辑视频支持多种格式(mov, mp4, 3gp); 新增相册名字等多语言,以完善手动设置语言时相册名字跟随系统的问题; 简化相册调用,configuration 由必传参数修改为非必传参数; ● 2.5.2: 提取相册配置参数独立为'ZLPhotoConfiguration'对象; 新增状态栏样式api; 优化部分代码; ● 2.5.1: ①:新增自定义相机(仿微信),开发者可选使用自定义相机或系统相机; diff --git a/ZLPhotoBrowser.podspec b/ZLPhotoBrowser.podspec index 4d38cb2f..42fc2f82 100644 --- a/ZLPhotoBrowser.podspec +++ b/ZLPhotoBrowser.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ZLPhotoBrowser' - s.version = '2.5.3' + s.version = '2.5.4' s.summary = 'A simple way to multiselect photos from ablum, force touch to preview photo, support portrait and landscape, edit photo, multiple languages(Chinese,English,Japanese)' s.homepage = 'https://github.com/longitachi/ZLPhotoBrowser' s.license = 'MIT' diff --git a/ZLPhotoBrowser/Info.plist b/ZLPhotoBrowser/Info.plist index 28f70a88..889d0b9e 100644 --- a/ZLPhotoBrowser/Info.plist +++ b/ZLPhotoBrowser/Info.plist @@ -19,7 +19,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 2.5.0.1 + 2.5.4 CFBundleSignature ???? CFBundleVersion