Bladeren bron

选择多个视频导致播放多次问题

jsonwang 3 jaren geleden
bovenliggende
commit
c3574cd2ca
1 gewijzigde bestanden met toevoegingen van 19 en 12 verwijderingen
  1. 19 12
      BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

+ 19 - 12
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -742,13 +742,15 @@ extension PQStuckPointEditerController {
             if synchroMarskView.superview == nil {
                 UIApplication.shared.keyWindow?.addSubview(synchroMarskView)
             }
+            let dispatchGroup = DispatchGroup()
 
             for photo in selectedPhotoData! {
                 if photo.asset != nil, photo.asset?.mediaType == .video{
                     if !isHaveVideo {
                         isHaveVideo = true
                     }
- 
+                    dispatchGroup.enter()
+
                     PQPHAssetVideoParaseUtil.parasToAVAsset(phAsset: photo.asset!) { avAsset, fileSize, _, _ in
                         if avAsset is AVURLAsset {
                             // 创建目录
@@ -774,24 +776,19 @@ extension PQStuckPointEditerController {
                                 }
                           
                                 do{
-                                           try FileManager.default.copyItem(atPath: fileName.replacingOccurrences(of: "file:///", with: ""), toPath: outFilePath)
-                                           print("Success to copy file.")
+                                    try FileManager.default.copyItem(atPath: fileName.replacingOccurrences(of: "file:///", with: ""), toPath: outFilePath)
+                                    print("Success to copy file.")
                                 }catch{
-                                           print("Failed to copy file.")
+                                    print("Failed to copy file.")
                                 }
  
                                 tempPhoto?.locationPath = outFilePath.replacingOccurrences(of: documensDirectory, with: "")
                                 BFLog(message: "导出视频相册地址为 \(String(describing: tempPhoto?.locationPath))")
-                            }
- 
-                            DispatchQueue.main.async {
-                                self.isExportVideosSuccess = true
-                                BFLog(message: "所有相册视频导出成功")
-                              
-                                    self.dealWithDataSuccess()
                                 
+                                dispatchGroup.leave()
+
                             }
-                            
+  
                         }
                     }
              
@@ -799,6 +796,16 @@ extension PQStuckPointEditerController {
                 }
             }
             
+            dispatchGroup.notify(queue: DispatchQueue.main) { [weak self] in
+                self?.isExportVideosSuccess = true
+                BFLog(message: "所有相册视频导出成功")
+                // 处理所有数据完成
+                if isHaveVideo {
+                    self?.dealWithDataSuccess()
+                }
+            }
+
+            
             //只有图片
             if(!isHaveVideo){
                 self.isExportVideosSuccess = true