获取视频拍摄后的缩率图展示到拍摄页面的左下角
This commit is contained in:
parent
469dddeff1
commit
8a6c0b365e
Binary file not shown.
@ -387,8 +387,8 @@
|
||||
filePath = "SwiftProject/Project/Controller/RecordingVideo/CCSpatialShootController.swift"
|
||||
startingColumnNumber = "9223372036854775807"
|
||||
endingColumnNumber = "9223372036854775807"
|
||||
startingLineNumber = "1176"
|
||||
endingLineNumber = "1176"
|
||||
startingLineNumber = "1223"
|
||||
endingLineNumber = "1223"
|
||||
landmarkName = "compositeSpatialPhoto()"
|
||||
landmarkType = "7">
|
||||
</BreakpointContent>
|
||||
|
||||
@ -848,29 +848,76 @@ class CCSpatialShootController: BaseController {
|
||||
|
||||
//MARK: - 获取相册第一张图片
|
||||
func getAlbumFirstPhoto() {
|
||||
PHPhotoLibrary.requestAuthorization(for: .readWrite) { (status) in
|
||||
PHPhotoLibrary.requestAuthorization(for: .readWrite) {[weak self] (status) in
|
||||
if status == PHAuthorizationStatus.authorized {
|
||||
let fetchOptions = PHFetchOptions()
|
||||
fetchOptions.sortDescriptors = [NSSortDescriptor(key:"creationDate", ascending: false)]
|
||||
|
||||
let assetsFetchResults: PHFetchResult<PHAsset>! = PHAsset.fetchAssets(with: .image, options: fetchOptions)
|
||||
let image_assetsFetchResults: PHFetchResult<PHAsset>! = PHAsset.fetchAssets(with: .image, options: fetchOptions)
|
||||
|
||||
if let asset = assetsFetchResults.firstObject {
|
||||
let imageManager = PHCachingImageManager()
|
||||
let video_assetsFetchResults: PHFetchResult<PHAsset>! = PHAsset.fetchAssets(with: .video, options: fetchOptions)
|
||||
|
||||
let requestOptions = PHImageRequestOptions()
|
||||
requestOptions.isSynchronous = true
|
||||
requestOptions.deliveryMode = .highQualityFormat
|
||||
let imgAsset = image_assetsFetchResults.firstObject
|
||||
let videoAsset = video_assetsFetchResults.firstObject
|
||||
var defaultAsset:PHAsset?
|
||||
if let imgAsset {
|
||||
defaultAsset = imgAsset
|
||||
}
|
||||
|
||||
imageManager.requestImageDataAndOrientation(for: asset, options: requestOptions) { imageData, dataUTI, imagePropertyOrientation, info in
|
||||
if let imageData = imageData {
|
||||
DispatchQueue.main.async {
|
||||
self.albumButton.setBackgroundImage(UIImage(data: imageData), for: .normal)
|
||||
}
|
||||
if let videoAsset{
|
||||
if let temp = defaultAsset {
|
||||
if (videoAsset.creationDate ?? Date.now > imgAsset?.creationDate ?? Date.now) {
|
||||
defaultAsset = videoAsset
|
||||
}
|
||||
}
|
||||
else {
|
||||
defaultAsset = videoAsset
|
||||
}
|
||||
}
|
||||
|
||||
if let defaultAsset {
|
||||
self?.getImageFromAsset(asset: defaultAsset)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// if let asset = image_assetsFetchResults.firstObject {
|
||||
// let imageManager = PHCachingImageManager()
|
||||
//
|
||||
// let requestOptions = PHImageRequestOptions()
|
||||
// requestOptions.isSynchronous = true
|
||||
// requestOptions.deliveryMode = .highQualityFormat
|
||||
//
|
||||
// imageManager.requestImageDataAndOrientation(for: asset, options: requestOptions) { imageData, dataUTI, imagePropertyOrientation, info in
|
||||
// if let imageData = imageData {
|
||||
// DispatchQueue.main.async {
|
||||
// self.albumButton.setBackgroundImage(UIImage(data: imageData), for: .normal)
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// print("没有获取到所旅途.....")
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// print("22222没有获取到所旅途.....")
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getImageFromAsset(asset:PHAsset){
|
||||
//处理模型
|
||||
let requestOptions = PHImageRequestOptions()
|
||||
requestOptions.isSynchronous = false//设置成同步回调
|
||||
requestOptions.deliveryMode = .highQualityFormat
|
||||
PHImageManager.default().requestImageDataAndOrientation(for: asset, options: requestOptions) {[weak self] data, dataUTI, imagePropertyOrientation, info in
|
||||
if let hasData = data {
|
||||
DispatchQueue.main.async {
|
||||
self?.albumButton.setBackgroundImage(UIImage(data: hasData), for: .normal)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1070,10 +1117,10 @@ extension CCSpatialShootController: AVCaptureFileOutputRecordingDelegate {
|
||||
private func saveVideoToLibrary(videoURL: URL) {
|
||||
PHPhotoLibrary.shared().performChanges({
|
||||
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoURL)
|
||||
}) { success, error in
|
||||
}) {[weak self] success, error in
|
||||
if success {
|
||||
print("保存成功")
|
||||
// self?.getAlbumFirstPhoto()
|
||||
self?.getAlbumFirstPhoto()
|
||||
} else if let error = error {
|
||||
print("保存失败")
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user