Selaa lähdekoodia

Merge branch 'master' of https://git.yishihui.com/iOS/BFFramework
合并代码

jsonwang 3 vuotta sitten
vanhempi
commit
4a8b216212

+ 2 - 1
BFFramework/Classes/PQGPUImage/akfilters/Tools/PQCompositionExporter.swift

@@ -166,13 +166,14 @@ public class PQCompositionExporter {
     }
     
  
-   public  func  findShowStikcer(currTime:Float64)  {
+    public  func  findShowStikcer(currTime:Float64)  {
          
         if(mStickers?.count ?? 0 == 0){
             BFLog(message: "mStickers data is error")
             return
         }
         var currentSticker:PQEditVisionTrackMaterialsModel?
+       
         for sticker in mStickers! {
             BFLog(message: "sticker in \(sticker.timelineIn) out \(sticker.timelineOut)  currTime is \(currTime)")
             if(sticker.timelineIn <= currTime && sticker.timelineOut >= currTime){

+ 42 - 20
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -1122,7 +1122,7 @@ class PQStuckPointEditerController: PQBaseViewController {
 
         let beginTime = Date()
         dealParameter(model: currentCreateStickersModel)
-
+        
         // 更新裁剪时间条的的ui数据
         stuckPointCuttingView.videoDuration = max(CGFloat(finallyUserAudioTime), CGFloat(finallyStuckPoints.last!))
         let counn = (stuckPointMusicData?.rhythmSdata[0].pointTimes.count)! - 2
@@ -1544,9 +1544,9 @@ extension PQStuckPointEditerController {
         }
         stuckPoints.insert(Float(stuckPointMusicData?.startTime ?? 0), at: 0)
 
-        for point in stuckPoints {
-            BFLog(message: "有 start end 计算后的卡点数\(point)")
-        }
+//        for point in stuckPoints {
+//            BFLog(message: "有 start end 计算后的卡点数\(point)")
+//        }
 
         BFLog(message: "处理节奏后 stuckPoints count is \(stuckPoints.count) seed \(seed), start time:\(stuckPoints.first ?? 0.0),end time:\(stuckPoints.last ?? 0.0) 总时长为:\((stuckPoints.last ?? 0.0) - (stuckPoints.first ?? 0.0))")
 
@@ -1743,6 +1743,12 @@ extension PQStuckPointEditerController {
 
             break
         }
+        
+        if finallyStuckPoints.count < 2 {
+            cShowHUB(superView: nil, msg: "视频资源导入失败,请重新选择!!")
+            exportResourceFailed()
+            return
+        }
         // 拼接图片所使用的时长.选择一组图片 按图片数量计算卡点的总时长
         if selectedImageDataCount > 0 {
             clipPoint(clipNum: selectedImageDataCount - 1, oldPoints: stuckPointsTemp)
@@ -1856,7 +1862,7 @@ extension PQStuckPointEditerController {
                     self?.synchroMarskView.removeMarskView()
                     cShowHUB(superView: nil, msg: "音乐信息加载失败,请重新选择音乐")
 //                    PQUploadRemindView.showUploadRemindView(title: nil, attributedTitle: NSAttributedString(string: "加载音乐失败,请重新选择音乐"), summary: "", confirmTitle: nil) { [weak self] _, _ in
-//                        self?.navigationController?.popViewController(animated: true)
+                        self?.navigationController?.popViewController(animated: true)
 //                    }
                 }
             }
@@ -1875,6 +1881,7 @@ extension PQStuckPointEditerController {
             exportSession.cancelExport()
         }
         var isHaveVideo: Bool = false
+        var failedExprot: Bool = false
         if selectedMetarialData != nil, (selectedMetarialData?.count ?? 0) > 0 {
             if synchroMarskView.superview == nil {
                 UIApplication.shared.keyWindow?.addSubview(synchroMarskView)
@@ -1910,23 +1917,26 @@ extension PQStuckPointEditerController {
                                         BFLog(message: "导出相册视频-error == \(error)")
                                     }
                                 }
+                                let curr = Date()
+                                let assetResources = PHAssetResource.assetResources(for: photo.asset!)
+                                if let rsc = assetResources.first(where: { res in
+                                    res.type == .video  || res.type == .pairedVideo
+                                }) {
+                                    PHAssetResourceManager.default().writeData(for: rsc, toFile: URL(fileURLWithPath: outFilePath), options: nil) { error in
+                                        if error == nil {
+                                            BFLog(message: "导出视频相exportAsynchronously \(String(describing: outFilePath)) \(Date().timeIntervalSince(curr))")
+                                            tempPhoto?.locationPath = outFilePath.replacingOccurrences(of: documensDirectory, with: "")
+                                        }else{
+                                            failedExprot = true
+                                            BFLog(message: "导出视频相exportAsynchro faile")
+                                        }
+                                        dispatchGroup.leave()
+                                    }
 
-                                do {
-                                    try FileManager.default.copyItem(atPath: fileName.replacingOccurrences(of: "file:///", with: ""), toPath: outFilePath)
-                                    print("Success to copy file.")
-                                } catch {
-                                    print("Failed to copy file.")
+                                }else {
+                                    BFLog(message: "导出视频相exportAsynchro faile")
+                                    dispatchGroup.leave()
                                 }
-
-                                tempPhoto?.locationPath = outFilePath.replacingOccurrences(of: documensDirectory, with: "")
-                                BFLog(message: "导出视频相册地址为 \(String(describing: tempPhoto?.locationPath))")
-
-                                dispatchGroup.leave()
-                            }
-                        }else {
-                            // 结束loading动画
-                            DispatchQueue.main.async {
-                                self.synchroMarskView.removeMarskView()
                             }
                         }
                     }
@@ -1934,6 +1944,11 @@ extension PQStuckPointEditerController {
             }
 
             dispatchGroup.notify(queue: DispatchQueue.main) { [weak self] in
+                if failedExprot {
+                    cShowHUB(superView: nil, msg: "视频导入失败,请返回重试")
+                    self?.exportResourceFailed()
+                    return
+                }
                 self?.isExportVideosSuccess = true
                 BFLog(message: "所有相册视频导出成功")
                 // 处理所有数据完成
@@ -1951,6 +1966,13 @@ extension PQStuckPointEditerController {
             }
         }
     }
+    
+    func exportResourceFailed(){
+        DispatchQueue.main.async {
+            self.synchroMarskView.removeMarskView()
+            self.navigationController?.popViewController(animated: true)
+        }
+    }
 
     /// 处理所有数据完成
     /// - Returns: <#description#>

+ 3 - 3
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointMusicContentController.swift

@@ -245,10 +245,10 @@ extension PQStuckPointMusicContentController: UICollectionViewDelegate, UICollec
 
     func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
         let itemData: Any = itemList[indexPath.item]
-        if itemData is ([PQStuckPointMusicTagsModel], ([UICollectionViewLayoutAttributes], CGFloat)) {
-            let height: CGFloat = ((itemData as? ([PQStuckPointMusicTagsModel], ([UICollectionViewLayoutAttributes], CGFloat)))?.0.count ?? 0) > 0 ? (((itemData as? ([PQStuckPointMusicTagsModel], ([UICollectionViewLayoutAttributes], CGFloat)))?.1.1 ?? 0) + 35) : 0
+        if let sul = itemData as? ([PQStuckPointMusicTagsModel], ([UICollectionViewLayoutAttributes], CGFloat)) {
+            let height: CGFloat = (sul.0.count > 0) ? (sul.1.1  + 35) : 0
             return CGSize(width: collectionView.frame.width, height: height)
-        } else if itemData is PQEmptyModel {
+        }else if itemData is PQEmptyModel {
             return CGSize(width: collectionView.frame.width, height: 290)
         } else {
             return CGSize(width: collectionView.frame.width, height: cellHight)

+ 3 - 3
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointPublicController.swift

@@ -1484,9 +1484,9 @@ extension PQStuckPointPublicController {
 //        emptyRemindView.isHidden = true
         emptyRemindView.emptyData = emptyData
         emptyRemindView.backgroundColor = PQBFConfig.shared.styleBackGroundColor
-        emptyRemindView.fullRefreshBloc = {[weak self] _, _ in
-            if emptyRemindView.refreshBtn.currentAttributedTitle?.string == "立即重试" {
-                emptyRemindView.isHidden = true
+        emptyRemindView.fullRefreshBloc = {[weak self, weak emptyRemindView] _, _ in
+            if emptyRemindView?.refreshBtn.currentAttributedTitle?.string == "立即重试" {
+                emptyRemindView?.isHidden = true
                 // 重试逻辑
                 if let message = msg{
                     if message.contains("token") {