|
@@ -31,6 +31,7 @@ class PublishUploadManager: NSObject {
|
|
|
|
|
|
// 图片上传参数
|
|
|
var imageArr: Array<UIImage>?
|
|
|
+ var imageAssetUrlArr: Array<String>?
|
|
|
|
|
|
// 发布参数
|
|
|
var selTopicIdArr: Array<String> = []
|
|
@@ -45,16 +46,21 @@ class PublishUploadManager: NSObject {
|
|
|
// 发布图片のUrlArray
|
|
|
var imageUrlArray: Array<String> = []
|
|
|
|
|
|
- var uploadManager: AlivcShortVideoUploadManager?
|
|
|
+ // 记录当前是否发布完成
|
|
|
+ var isPublishFinished: Bool = true
|
|
|
+ // 图片上传时当前循环次数
|
|
|
+ var curTimes: Int = 0
|
|
|
+ // 是否正在上传视频封面
|
|
|
+ var isUploadingVideoCover: Bool = false
|
|
|
|
|
|
+ var uploadManager: AlivcShortVideoUploadManager?
|
|
|
|
|
|
var progressView: PublishUploadProgressView?
|
|
|
- // 记录当前是否发布完成
|
|
|
- var isPublishFinished: Bool = true
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// MARK: - 视频上传流程
|
|
|
-extension PublishUploadManager: AlivcShortVideoUploadManagerDelegate {
|
|
|
+extension PublishUploadManager {
|
|
|
|
|
|
// 设置视频上传参数
|
|
|
func setVideoPath(_ mediaType: PublishMediaType, _ videoPath: String, _ coverImagePath: String, _ videoImage: UIImage) {
|
|
@@ -62,9 +68,11 @@ extension PublishUploadManager: AlivcShortVideoUploadManagerDelegate {
|
|
|
self.videoPath = videoPath
|
|
|
self.coverImagePath = coverImagePath
|
|
|
self.videoImage = videoImage
|
|
|
+ // 新发布时还原管理类内部的变量
|
|
|
+ self.isUploadingVideoCover = false
|
|
|
}
|
|
|
|
|
|
- // 获取上传地址和凭证
|
|
|
+ // 获取上传地址和凭证(视频)
|
|
|
func communityVideoUploadAuthApi() {
|
|
|
isPublishFinished = false
|
|
|
|
|
@@ -80,7 +88,6 @@ extension PublishUploadManager: AlivcShortVideoUploadManagerDelegate {
|
|
|
self?.paraVideo = communityVideoAuthModel?.videoId ?? ""
|
|
|
self?.startUploadVideo(communityVideoAuthModel!)
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
// 上传视频
|
|
@@ -95,102 +102,152 @@ extension PublishUploadManager: AlivcShortVideoUploadManagerDelegate {
|
|
|
uploadManager?.startUpload()
|
|
|
}
|
|
|
|
|
|
- // 上传进度回调
|
|
|
- func uploadManager(_ manager: AlivcShortVideoUploadManager!, updateProgress progress: CGFloat) {
|
|
|
- NXLLog("\n--------uploadProgress == \(progress)")
|
|
|
-
|
|
|
- DispatchQueue.main.async(execute: {
|
|
|
-// self.progressView.progress = Float(progress)
|
|
|
- self.progressView?.uploadProgress = Float(progress)
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- // 上传状态回调
|
|
|
- func uploadManager(_ manager: AlivcShortVideoUploadManager!, uploadStatusChangedTo newStatus: AlivcUploadStatus) {
|
|
|
- switch newStatus {
|
|
|
- case AlivcUploadStatus.failure:
|
|
|
- DispatchQueue.main.async(execute: {
|
|
|
- SwiftProgressHUD.shared().showText("上传失败!")
|
|
|
- })
|
|
|
+ // 获取上传地址和凭证(图片)
|
|
|
+ func videoCoverImageUploadAuth() {
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityImageUploadAuth {
|
|
|
+ [weak self] (communityImageAuthModel) -> (Void) in
|
|
|
+ let communityImageAuthModel = communityImageAuthModel as? CommunityImageAuthModel
|
|
|
|
|
|
- case AlivcUploadStatus.success:
|
|
|
- // 上传封面图
|
|
|
- self.uploadVideoCoverImage()
|
|
|
+ let imgWidth = Int(self?.videoImage!.size.width ?? 0)
|
|
|
+ let imgHeight = Int(self?.videoImage!.size.height ?? 0)
|
|
|
+ let urlStr = String(format: "%@?%ld_%ld", communityImageAuthModel?.imageURL ?? "", imgWidth, imgHeight)
|
|
|
+ // 设置主图
|
|
|
+ self?.majorImageUrl = urlStr
|
|
|
|
|
|
- default:
|
|
|
- break
|
|
|
+ self?.uploadVideoCoverImage(communityImageAuthModel!)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 上传视频封面图
|
|
|
- func uploadVideoCoverImage() {
|
|
|
- SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgWithoutHudApi(imageArray: [videoImage!]) {
|
|
|
- [weak self] (imgUrl) -> (Void) in
|
|
|
- // 设置主图
|
|
|
- self?.majorImageUrl = imgUrl as? String
|
|
|
-
|
|
|
- NXLLog("------视频上传成功,去发布")
|
|
|
- self?.progressView?.curUploadStatus = .success
|
|
|
- self?.communityPublishApi()
|
|
|
- }
|
|
|
+ func uploadVideoCoverImage(_ authModel: CommunityImageAuthModel) {
|
|
|
+ self.isUploadingVideoCover = true
|
|
|
+
|
|
|
+ uploadManager = AlivcShortVideoUploadManager.shared()
|
|
|
+ uploadManager?.setCoverImagePath(coverImagePath, videoInfo: nil, videoPath: "")
|
|
|
+ uploadManager?.managerDelegate = self
|
|
|
+ uploadManager?.uploadAddress = authModel.uploadAddress
|
|
|
+ uploadManager?.uploadAuth = authModel.uploadAuth
|
|
|
+ uploadManager?.startUpload()
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// MARK: - 图片上传流程
|
|
|
extension PublishUploadManager {
|
|
|
|
|
|
// 设置图片上传参数
|
|
|
- func setImagesPath(_ imageArr: Array<UIImage>) {
|
|
|
+ func setImagesPath(_ imageArr: Array<UIImage>, _ imageUrlArr: Array<String>) {
|
|
|
self.imageArr = imageArr
|
|
|
- // 新发布时置空管理类内部的imageUrl数组
|
|
|
+ self.imageAssetUrlArr = imageUrlArr
|
|
|
+ // 新发布时置空管理类内部的imageUrl数组及循环次数
|
|
|
self.imageUrlArray = []
|
|
|
+ self.curTimes = 0
|
|
|
}
|
|
|
|
|
|
- // 上传图片
|
|
|
- func uploadAllImages(totalTimes: Int) {
|
|
|
+ // 获取上传地址和凭证(图片)
|
|
|
+ func communityImageUploadAuth(totalTimes: Int) {
|
|
|
isPublishFinished = false
|
|
|
|
|
|
- var curTimes: Int = totalTimes
|
|
|
-
|
|
|
- NXLLog("-----StartUpload,totalTimes == \(totalTimes)")
|
|
|
- SwiftMoyaNetWorkServiceConfig.shared().configUploadSingleImgWithoutHudApi(imageArray: [self.imageArr![totalTimes]]) {
|
|
|
- [weak self] (imgUrl) -> (Void) in
|
|
|
- let urlStr: String = imgUrl as! String
|
|
|
-
|
|
|
-// let curImage: UIImage = self!.imageArr![totalTimes]
|
|
|
-// let imgWidth = curImage.size.width
|
|
|
-// let imgHeight = curImage.size.height
|
|
|
-// urlStr = String(format: "%@?%f_%f", urlStr, imgWidth, imgHeight)
|
|
|
+ SwiftMoyaNetWorkServiceCommunity.shared().communityImageUploadAuth {
|
|
|
+ [weak self] (communityImageAuthModel) -> (Void) in
|
|
|
+ let communityImageAuthModel = communityImageAuthModel as? CommunityImageAuthModel
|
|
|
|
|
|
+ let curImage: UIImage = self?.imageArr![totalTimes] ?? UIImage()
|
|
|
+ let imgWidth = Int(curImage.size.width)
|
|
|
+ let imgHeight = Int(curImage.size.height)
|
|
|
+ let urlStr = String(format: "%@?%ld_%ld", communityImageAuthModel?.imageURL ?? "", imgWidth, imgHeight)
|
|
|
self?.imageUrlArray.append(urlStr)
|
|
|
- if curTimes == 0 {
|
|
|
- // 设置主图
|
|
|
- self?.majorImageUrl = urlStr
|
|
|
- }
|
|
|
|
|
|
- NXLLog("-----FinishUpload,Times == \(curTimes)")
|
|
|
- curTimes += 1
|
|
|
- // 更新进度
|
|
|
- DispatchQueue.main.async {
|
|
|
- NXLLog("----\(Thread.current)")
|
|
|
- NXLLog("----uploadProgress == \(Float(curTimes)/Float((self?.imageArr!.count)!))")
|
|
|
-
|
|
|
- self?.progressView?.uploadProgress = Float(curTimes/(self?.imageArr!.count)!)
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- if curTimes < self?.imageArr?.count ?? 0 {
|
|
|
- self?.uploadAllImages(totalTimes: curTimes)
|
|
|
+ self?.startUploadImage(communityImageAuthModel!, totalTimes)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传图片
|
|
|
+ func startUploadImage(_ authModel: CommunityImageAuthModel, _ totalTimes: Int) {
|
|
|
+ self.curTimes = totalTimes
|
|
|
+
|
|
|
+ let info = AliyunUploadSVideoInfo()
|
|
|
+ uploadManager = AlivcShortVideoUploadManager.shared()
|
|
|
+ uploadManager?.setCoverImagePath(self.imageAssetUrlArr?[totalTimes], videoInfo: nil, videoPath: "")
|
|
|
+ uploadManager?.managerDelegate = self
|
|
|
+ uploadManager?.uploadAddress = authModel.uploadAddress
|
|
|
+ uploadManager?.uploadAuth = authModel.uploadAuth
|
|
|
+ uploadManager?.startUpload()
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - 上传过程监听
|
|
|
+extension PublishUploadManager: AlivcShortVideoUploadManagerDelegate {
|
|
|
+
|
|
|
+ // 上传进度回调
|
|
|
+ func uploadManager(_ manager: AlivcShortVideoUploadManager!, updateProgress progress: CGFloat) {
|
|
|
+ NXLLog("-------------------上传进度回调 - progress == \(progress)")
|
|
|
+ DispatchQueue.main.async(execute: {
|
|
|
+ if self.mediaType == .image {
|
|
|
+ NXLLog("\n--------\(self.curTimes) uploadProgress == \(progress)")
|
|
|
} else {
|
|
|
- NXLLog("------图片上传成功,去发布")
|
|
|
- self?.progressView?.curUploadStatus = .success
|
|
|
- self?.communityPublishApi()
|
|
|
+ self.progressView?.uploadProgress = Float(progress)
|
|
|
}
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传状态回调
|
|
|
+ func uploadManager(_ manager: AlivcShortVideoUploadManager!, uploadStatusChangedTo newStatus: AlivcUploadStatus) {
|
|
|
+ switch newStatus {
|
|
|
+ case AlivcUploadStatus.failure:
|
|
|
+ DispatchQueue.main.async(execute: {
|
|
|
+ SwiftProgressHUD.shared().showText("上传失败!")
|
|
|
+ print("----------上传失败!")
|
|
|
+ self.isPublishFinished = true
|
|
|
+ })
|
|
|
+
|
|
|
+ case AlivcUploadStatus.success:
|
|
|
+ DispatchQueue.main.async(execute: {
|
|
|
+ if self.mediaType == .image {
|
|
|
+ // 图片上传流程
|
|
|
+ self.curTimes += 1
|
|
|
+
|
|
|
+ // 更新进度
|
|
|
+ NXLLog("----uploadProgress == \(Float(self.curTimes)/Float(self.imageArr!.count))")
|
|
|
+ self.progressView?.uploadProgress = Float(self.curTimes/self.imageArr!.count)
|
|
|
+
|
|
|
+ if self.curTimes < self.imageArr?.count ?? 0 {
|
|
|
+ // 继续上传
|
|
|
+ self.communityImageUploadAuth(totalTimes: self.curTimes)
|
|
|
+ } else {
|
|
|
+ // 图片上传成功,去发布
|
|
|
+ // 设置主图
|
|
|
+ self.majorImageUrl = self.imageUrlArray[0]
|
|
|
+ self.progressView?.curUploadStatus = .success
|
|
|
+ self.communityPublishApi()
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 视频上传流程
|
|
|
+ if self.isUploadingVideoCover {
|
|
|
+ // 上传封面图の返回
|
|
|
+ self.isUploadingVideoCover = false
|
|
|
+
|
|
|
+ // 视频上传成功,去发布
|
|
|
+ self.progressView?.curUploadStatus = .success
|
|
|
+ self.communityPublishApi()
|
|
|
+
|
|
|
+ } else {
|
|
|
+ // 上传视频の返回
|
|
|
+ self.videoCoverImageUploadAuth()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ default:
|
|
|
+ break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
// MARK: - 发布流程
|
|
|
extension PublishUploadManager {
|
|
|
|
|
@@ -237,6 +294,7 @@ extension PublishUploadManager {
|
|
|
isPublishFinished = true
|
|
|
progressView?.hide()
|
|
|
progressView?.attachedView?.isHidden = true
|
|
|
+
|
|
|
// progressView?.curUploadStatus = UploadStatus.failure
|
|
|
}
|
|
|
}
|