Unverified Commit 96418dc0 authored by 谭真's avatar 谭真 Committed by GitHub

Merge pull request #786 from shushengwang/master

添加简单的视频录制
parents 5f1d484e c9627130
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
<string>允许定位以把位置保存到照片中</string> <string>允许定位以把位置保存到照片中</string>
<key>NSPhotoLibraryUsageDescription</key> <key>NSPhotoLibraryUsageDescription</key>
<string>访问相册以选择照片</string> <string>访问相册以选择照片</string>
<key>NSMicrophoneUsageDescription</key>
<string>访问麦克风以录像</string>
<key>UILaunchStoryboardName</key> <key>UILaunchStoryboardName</key>
<string>LaunchScreen</string> <string>LaunchScreen</string>
<key>UIMainStoryboardFile</key> <key>UIMainStoryboardFile</key>
......
...@@ -77,6 +77,10 @@ ...@@ -77,6 +77,10 @@
- (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion; - (void)savePhotoWithImage:(UIImage *)image completion:(void (^)(NSError *error))completion;
- (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(NSError *error))completion; - (void)savePhotoWithImage:(UIImage *)image location:(CLLocation *)location completion:(void (^)(NSError *error))completion;
/// Save video 保存视频
- (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(NSError *error))completion;
- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(NSError *error))completion;
/// Get video 获得视频 /// Get video 获得视频
- (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion; - (void)getVideoWithAsset:(id)asset completion:(void (^)(AVPlayerItem * playerItem, NSDictionary * info))completion;
- (void)getVideoWithAsset:(id)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem *, NSDictionary *))completion; - (void)getVideoWithAsset:(id)asset progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler completion:(void (^)(AVPlayerItem *, NSDictionary *))completion;
......
...@@ -690,6 +690,61 @@ static dispatch_once_t onceToken; ...@@ -690,6 +690,61 @@ static dispatch_once_t onceToken;
} }
} }
#pragma mark - Save video
- (void)saveVideoWithUrl:(NSURL *)url completion:(void (^)(NSError *error))completion {
[self saveVideoWithUrl:url location:nil completion:completion];
}
- (void)saveVideoWithUrl:(NSURL *)url location:(CLLocation *)location completion:(void (^)(NSError *error))completion {
if (iOS8Later) {
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
if (iOS9Later) {
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.shouldMoveFile = YES;
PHAssetCreationRequest *request = [PHAssetCreationRequest creationRequestForAsset];
[request addResourceWithType:PHAssetResourceTypeVideo fileURL:url options:options];
if (location) {
request.location = location;
}
request.creationDate = [NSDate date];
} else {
PHAssetChangeRequest *request = [PHAssetChangeRequest creationRequestForAssetFromVideoAtFileURL:url];
if (location) {
request.location = location;
}
request.creationDate = [NSDate date];
}
} completionHandler:^(BOOL success, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
if (success && completion) {
completion(nil);
} else if (error) {
NSLog(@"保存视频出错:%@",error.localizedDescription);
if (completion) {
completion(error);
}
}
});
}];
} else {
[self.assetLibrary writeVideoAtPathToSavedPhotosAlbum:url completionBlock:^(NSURL *assetURL, NSError *error) {
if (error) {
NSLog(@"保存视频出错:%@",error.localizedDescription);
if (completion) {
completion(error);
}
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (completion) {
completion(nil);
}
});
}
}];
}
}
#pragma mark - Get Video #pragma mark - Get Video
/// Get Video / 获取视频 /// Get Video / 获取视频
......
...@@ -605,6 +605,10 @@ static CGFloat itemMargin = 5; ...@@ -605,6 +605,10 @@ static CGFloat itemMargin = 5;
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) { if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
self.imagePickerVc.sourceType = sourceType; self.imagePickerVc.sourceType = sourceType;
TZImagePickerController *tzImagePickerVc = (TZImagePickerController *)self.navigationController;
if (tzImagePickerVc.allowPickingVideo) {
self.imagePickerVc.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeCamera];
}
if(iOS8Later) { if(iOS8Later) {
_imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext; _imagePickerVc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
} }
...@@ -726,6 +730,18 @@ static CGFloat itemMargin = 5; ...@@ -726,6 +730,18 @@ static CGFloat itemMargin = 5;
}]; }];
self.location = nil; self.location = nil;
} }
} else if ([type isEqualToString:@"public.movie"]) {
TZImagePickerController *imagePickerVc = (TZImagePickerController *)self.navigationController;
[imagePickerVc showProgressHUD];
NSURL *videoUrl = [info objectForKey:UIImagePickerControllerMediaURL];
if (videoUrl) {
[[TZImageManager manager] saveVideoWithUrl:videoUrl location:self.location completion:^(NSError *error) {
if (!error) {
[self reloadPhotoArray];
}
}];
self.location = nil;
}
} }
} }
...@@ -739,11 +755,15 @@ static CGFloat itemMargin = 5; ...@@ -739,11 +755,15 @@ static CGFloat itemMargin = 5;
TZAssetModel *assetModel; TZAssetModel *assetModel;
if (tzImagePickerVc.sortAscendingByModificationDate) { if (tzImagePickerVc.sortAscendingByModificationDate) {
assetModel = [models lastObject]; assetModel = [models lastObject];
if (assetModel.type != TZAssetModelMediaTypeVideo || tzImagePickerVc.allowPickingMultipleVideo) {
[_models addObject:assetModel]; [_models addObject:assetModel];
}
} else { } else {
assetModel = [models firstObject]; assetModel = [models firstObject];
if (assetModel.type != TZAssetModelMediaTypeVideo || tzImagePickerVc.allowPickingMultipleVideo) {
[_models insertObject:assetModel atIndex:0]; [_models insertObject:assetModel atIndex:0];
} }
}
if (tzImagePickerVc.maxImagesCount <= 1) { if (tzImagePickerVc.maxImagesCount <= 1) {
if (tzImagePickerVc.allowCrop) { if (tzImagePickerVc.allowCrop) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment