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
96418dc0
Unverified
Commit
96418dc0
authored
Apr 08, 2018
by
谭真
Committed by
GitHub
Apr 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #786 from shushengwang/master
添加简单的视频录制
parents
5f1d484e
c9627130
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
2 deletions
+83
-2
TZImagePickerController/Info.plist
TZImagePickerController/Info.plist
+2
-0
TZImagePickerController/TZImagePickerController/TZImageManager.h
...PickerController/TZImagePickerController/TZImageManager.h
+4
-0
TZImagePickerController/TZImagePickerController/TZImageManager.m
...PickerController/TZImagePickerController/TZImageManager.m
+55
-0
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
...troller/TZImagePickerController/TZPhotoPickerController.m
+22
-2
No files found.
TZImagePickerController/Info.plist
View file @
96418dc0
...
...
@@ -28,6 +28,8 @@
<string>
允许定位以把位置保存到照片中
</string>
<key>
NSPhotoLibraryUsageDescription
</key>
<string>
访问相册以选择照片
</string>
<key>
NSMicrophoneUsageDescription
</key>
<string>
访问麦克风以录像
</string>
<key>
UILaunchStoryboardName
</key>
<string>
LaunchScreen
</string>
<key>
UIMainStoryboardFile
</key>
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.h
View file @
96418dc0
...
...
@@ -77,6 +77,10 @@
-
(
void
)
savePhotoWithImage
:(
UIImage
*
)
image
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 获得视频
-
(
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
;
...
...
TZImagePickerController/TZImagePickerController/TZImageManager.m
View file @
96418dc0
...
...
@@ -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
/// Get Video / 获取视频
...
...
TZImagePickerController/TZImagePickerController/TZPhotoPickerController.m
View file @
96418dc0
...
...
@@ -605,6 +605,10 @@ static CGFloat itemMargin = 5;
UIImagePickerControllerSourceType
sourceType
=
UIImagePickerControllerSourceTypeCamera
;
if
([
UIImagePickerController
isSourceTypeAvailable
:
UIImagePickerControllerSourceTypeCamera
])
{
self
.
imagePickerVc
.
sourceType
=
sourceType
;
TZImagePickerController
*
tzImagePickerVc
=
(
TZImagePickerController
*
)
self
.
navigationController
;
if
(
tzImagePickerVc
.
allowPickingVideo
)
{
self
.
imagePickerVc
.
mediaTypes
=
[
UIImagePickerController
availableMediaTypesForSourceType
:
UIImagePickerControllerSourceTypeCamera
];
}
if
(
iOS8Later
)
{
_imagePickerVc
.
modalPresentationStyle
=
UIModalPresentationOverCurrentContext
;
}
...
...
@@ -726,6 +730,18 @@ static CGFloat itemMargin = 5;
}];
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;
TZAssetModel
*
assetModel
;
if
(
tzImagePickerVc
.
sortAscendingByModificationDate
)
{
assetModel
=
[
models
lastObject
];
if
(
assetModel
.
type
!=
TZAssetModelMediaTypeVideo
||
tzImagePickerVc
.
allowPickingMultipleVideo
)
{
[
_models
addObject
:
assetModel
];
}
}
else
{
assetModel
=
[
models
firstObject
];
if
(
assetModel
.
type
!=
TZAssetModelMediaTypeVideo
||
tzImagePickerVc
.
allowPickingMultipleVideo
)
{
[
_models
insertObject
:
assetModel
atIndex
:
0
];
}
}
if
(
tzImagePickerVc
.
maxImagesCount
<=
1
)
{
if
(
tzImagePickerVc
.
allowCrop
)
{
...
...
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