Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
dz_TZImagePickerController
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shuijing
dz_TZImagePickerController
Commits
88b5f37f
Commit
88b5f37f
authored
Nov 15, 2017
by
yuzheng.tz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化视频导出方法,当发生错误时调用失败回调透出错误信息
parent
3d1a48df
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
30 deletions
+54
-30
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+3
-1
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+44
-23
TZImagePickerController/ViewController.m
TZImagePickerController/ViewController.m
+7
-6
No files found.
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
88b5f37f
...
...
@@ -81,7 +81,9 @@
-
(
void
)
getVideoWithAsset
:(
id
)
asset
progressHandler
:(
void
(
^
)(
double
progress
,
NSError
*
error
,
BOOL
*
stop
,
NSDictionary
*
info
))
progressHandler
completion
:(
void
(
^
)(
AVPlayerItem
*
,
NSDictionary
*
))
completion
;
/// Export video 导出视频
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
;
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
;
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
__attribute__
((
deprecated
(
"Use -getVideoOutputPathWithAsset:failure:success:"
)));
/// Get photo bytes 获得一组照片的大小
-
(
void
)
getPhotosBytesWithArray
:(
NSArray
*
)
photos
completion
:(
void
(
^
)(
NSString
*
totalBytes
))
completion
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
88b5f37f
...
...
@@ -714,7 +714,7 @@ static dispatch_once_t onceToken;
#pragma mark - Export video
/// Export Video / 导出视频
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
{
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
{
if
([
asset
isKindOfClass
:[
PHAsset
class
]])
{
PHVideoRequestOptions
*
options
=
[[
PHVideoRequestOptions
alloc
]
init
];
options
.
version
=
PHVideoRequestOptionsVersionOriginal
;
...
...
@@ -724,16 +724,21 @@ static dispatch_once_t onceToken;
// NSLog(@"Info:\n%@",info);
AVURLAsset
*
videoAsset
=
(
AVURLAsset
*
)
avasset
;
// NSLog(@"AVAsset URL: %@",myAsset.URL);
[
self
startExportVideoWithVideoAsset
:
videoAsset
completion
:
completion
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
success
:
success
failure
:
failure
];
}];
}
else
if
([
asset
isKindOfClass
:[
ALAsset
class
]])
{
NSURL
*
videoURL
=
[
asset
valueForProperty
:
ALAssetPropertyAssetURL
];
// ALAssetPropertyURLs
AVURLAsset
*
videoAsset
=
[[
AVURLAsset
alloc
]
initWithURL
:
videoURL
options
:
nil
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
completion
:
completion
];
[
self
startExportVideoWithVideoAsset
:
videoAsset
success
:
success
failure
:
failure
];
}
}
-
(
void
)
startExportVideoWithVideoAsset
:(
AVURLAsset
*
)
videoAsset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
{
/// Deprecated, Use -getVideoOutputPathWithAsset:failure:success:
-
(
void
)
getVideoOutputPathWithAsset
:(
id
)
asset
completion
:(
void
(
^
)(
NSString
*
outputPath
))
completion
{
[
self
getVideoOutputPathWithAsset
:
asset
success
:
completion
failure
:
nil
];
}
-
(
void
)
startExportVideoWithVideoAsset
:(
AVURLAsset
*
)
videoAsset
success
:(
void
(
^
)(
NSString
*
outputPath
))
success
failure
:(
void
(
^
)(
NSString
*
errorMessage
,
NSError
*
error
))
failure
{
// Find compatible presets by video asset.
NSArray
*
presets
=
[
AVAssetExportSession
exportPresetsCompatibleWithAsset
:
videoAsset
];
...
...
@@ -747,7 +752,7 @@ static dispatch_once_t onceToken;
NSDateFormatter
*
formater
=
[[
NSDateFormatter
alloc
]
init
];
[
formater
setDateFormat
:
@"yyyy-MM-dd-HH:mm:ss-SSS"
];
NSString
*
outputPath
=
[
NSHomeDirectory
()
stringByAppendingFormat
:
@"/tmp/output-%@.mp4"
,
[
formater
stringFromDate
:[
NSDate
date
]]];
NSLog
(
@"video outputPath = %@"
,
outputPath
);
//
NSLog(@"video outputPath = %@",outputPath);
session
.
outputURL
=
[
NSURL
fileURLWithPath
:
outputPath
];
// Optimize for network use.
...
...
@@ -757,6 +762,9 @@ static dispatch_once_t onceToken;
if
([
supportedTypeArray
containsObject
:
AVFileTypeMPEG4
])
{
session
.
outputFileType
=
AVFileTypeMPEG4
;
}
else
if
(
supportedTypeArray
.
count
==
0
)
{
if
(
failure
)
{
failure
(
@"该视频类型暂不支持导出"
,
nil
);
}
NSLog
(
@"No supported file types 视频类型暂不支持导出"
);
return
;
}
else
{
...
...
@@ -775,25 +783,38 @@ static dispatch_once_t onceToken;
// Begin to export video to the output path asynchronously.
[
session
exportAsynchronouslyWithCompletionHandler
:
^
(
void
)
{
switch
(
session
.
status
)
{
case
AVAssetExportSessionStatusUnknown
:
NSLog
(
@"AVAssetExportSessionStatusUnknown"
);
break
;
case
AVAssetExportSessionStatusWaiting
:
NSLog
(
@"AVAssetExportSessionStatusWaiting"
);
break
;
case
AVAssetExportSessionStatusExporting
:
NSLog
(
@"AVAssetExportSessionStatusExporting"
);
break
;
case
AVAssetExportSessionStatusCompleted
:
{
NSLog
(
@"AVAssetExportSessionStatusCompleted"
);
dispatch_async
(
dispatch_get_main_queue
(),
^
{
if
(
completion
)
{
completion
(
outputPath
);
dispatch_async
(
dispatch_get_main_queue
(),
^
{
switch
(
session
.
status
)
{
case
AVAssetExportSessionStatusUnknown
:
{
NSLog
(
@"AVAssetExportSessionStatusUnknown"
);
}
break
;
case
AVAssetExportSessionStatusWaiting
:
{
NSLog
(
@"AVAssetExportSessionStatusWaiting"
);
}
break
;
case
AVAssetExportSessionStatusExporting
:
{
NSLog
(
@"AVAssetExportSessionStatusExporting"
);
}
break
;
case
AVAssetExportSessionStatusCompleted
:
{
NSLog
(
@"AVAssetExportSessionStatusCompleted"
);
if
(
success
)
{
success
(
outputPath
);
}
});
}
break
;
case
AVAssetExportSessionStatusFailed
:
NSLog
(
@"AVAssetExportSessionStatusFailed"
);
break
;
default:
break
;
}
}
break
;
case
AVAssetExportSessionStatusFailed
:
{
NSLog
(
@"AVAssetExportSessionStatusFailed"
);
if
(
failure
)
{
failure
(
@"视频导出失败"
,
session
.
error
);
}
}
break
;
case
AVAssetExportSessionStatusCancelled
:
{
NSLog
(
@"AVAssetExportSessionStatusCancelled"
);
if
(
failure
)
{
failure
(
@"导出任务已被取消"
,
nil
);
}
}
break
;
default:
break
;
}
});
}];
}
}
...
...
TZImagePickerController/ViewController.m
View file @
88b5f37f
...
...
@@ -496,12 +496,13 @@
_selectedPhotos
=
[
NSMutableArray
arrayWithArray
:@[
coverImage
]];
_selectedAssets
=
[
NSMutableArray
arrayWithArray
:@[
asset
]];
// open this code to send video / 打开这段代码发送视频
// [[TZImageManager manager] getVideoOutputPathWithAsset:asset completion:^(NSString *outputPath) {
// NSLog(@"视频导出到本地完成,沙盒路径为:%@",outputPath);
// Export completed, send video here, send by outputPath or NSData
// 导出完成,在这里写上传代码,通过路径或者通过NSData上传
// }];
[[
TZImageManager
manager
]
getVideoOutputPathWithAsset
:
asset
success
:
^
(
NSString
*
outputPath
)
{
NSLog
(
@"视频导出到本地完成,沙盒路径为:%@"
,
outputPath
);
// Export completed, send video here, send by outputPath or NSData
// 导出完成,在这里写上传代码,通过路径或者通过NSData上传
}
failure
:^
(
NSString
*
errorMessage
,
NSError
*
error
)
{
NSLog
(
@"视频导出失败:%@,error:%@"
,
errorMessage
,
error
);
}];
[
_collectionView
reloadData
];
// _collectionView.contentSize = CGSizeMake(0, ((_selectedPhotos.count + 2) / 3 ) * (_margin + _itemWH));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment