فهرست منبع

仅图片循环次数逻辑

jsonwang 3 سال پیش
والد
کامیت
cb44353155

+ 247 - 134
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -51,13 +51,15 @@ class PQStuckPointEditerController: PQBaseViewController {
     var lastEditModelBtn: UIButton?
     
     // add by ak  最大、最小速度 有固定值和自定义,当快慢速下两个值都有效,当跳跃卡点只有maxSpeed有效
-    var maxSpeed: Float = 0.0
-    var minSpeed: Float = 0.0
+    var maxSpeed: Float = 1
+    var minSpeed: Float = 1
     
     //快慢速最后一次选择的速度位置
     var lastSpeedSelectIndex:Int = 0
     //跳跃卡点最后一次选择的速度位置
     var lastJumpSpeedSelectIndex:Int = 0
+    //循环次数设置最后一次选择的位置
+    var lastCyclesSelectIndex:Int = 0
     
     //当前选择的玩法模式
     var currentCreateStickersModel:createStickersModel = .createStickersModelSpeed
@@ -319,15 +321,17 @@ class PQStuckPointEditerController: PQBaseViewController {
         speedSettingView.selectSpeedCallBack = { [weak self] maxSpeed, minSpeed,selectIndex in
             BFLog(message: "固定maxSpeed is\(maxSpeed) minSpeed \(minSpeed)")
             //更新最后一次选择的位置恢复时使用
-            if(speedSettingView.viewType == 2){
+            if(speedSettingView.viewType == 1){
+                self?.lastSpeedSelectIndex = selectIndex
+            }else if(speedSettingView.viewType == 2){
                 self?.lastJumpSpeedSelectIndex = selectIndex
             }else{
-                self?.lastSpeedSelectIndex = selectIndex
+                self?.lastCyclesSelectIndex = selectIndex
             }
             self?.maxSpeed = maxSpeed
             self?.minSpeed = minSpeed
-            if maxSpeed == 0 && minSpeed == 0 {
-                self?.customSpeedSettingView.isHidden = false
+            if maxSpeed == -1.0 && minSpeed == -1.0 {
+                self?.customSpeedSettingView.isHidden = true
                 self?.customSpeedSettingView.isJumpSpeedModel = speedSettingView.viewType == 2
             }
             self?.settingPlayerView()
@@ -484,49 +488,79 @@ class PQStuckPointEditerController: PQBaseViewController {
 
         BFLog(message: "sender tag is \(sender.tag)")
         // 1 ui 调整
-        if sender.tag == 1 || sender.tag == 2 {
-            speedSettingView.viewType = sender.tag
-            customSpeedSettingView.isJumpSpeedModel = speedSettingView.viewType == 2
-
+          if sender.tag == 1 || sender.tag == 2 {
+              speedSettingView.viewType = sender.tag
+              customSpeedSettingView.isJumpSpeedModel = speedSettingView.viewType == 2
+
+              speedSettingView.snp.remakeConstraints { make in
+                  make.left.equalToSuperview().offset(16)
+                  make.right.equalToSuperview()
+                  make.top.equalTo(editModelLineView.snp_bottom).offset(8)
+                  make.height.equalTo(sender.tag == 1 ? 44 : 30)
+              }
+              speedSettingView.isHidden = false
+              speedTitleLab.isHidden = false
+              sustomSwitchView.isHidden = false
+              editModelLineView.isHidden = false
+          } else {
+              
+              speedTitleLab.isHidden = true
+              speedSettingView.isHidden = true
+              editModelLineView.isHidden = true
+              sustomSwitchView.isHidden = true
+   
+          }
+        //素材全是图片的时候三个模式都显示循环设置 UI
+        if(selectedDataCount == selectedImageDataCount){
+            speedSettingView.viewType = 3
+            customSpeedSettingView.isJumpSpeedModel = false
             speedSettingView.snp.remakeConstraints { make in
                 make.left.equalToSuperview().offset(16)
                 make.right.equalToSuperview()
                 make.top.equalTo(editModelLineView.snp_bottom).offset(8)
-                make.height.equalTo(sender.tag == 1 ? 44 : 30)
+                make.height.equalTo(30)
             }
-            speedSettingView.isHidden = false
-            speedTitleLab.isHidden = false
-            sustomSwitchView.isHidden = false
-            editModelLineView.isHidden = false
-        } else {
-            speedSettingView.isHidden = true
-            speedTitleLab.isHidden = true
-            sustomSwitchView.isHidden = true
-            editModelLineView.isHidden = true
+            
+            speedSettingView.isHidden = !(selectedDataCount == selectedImageDataCount)
+            editModelLineView.isHidden = !(selectedDataCount == selectedImageDataCount)
+          
+            speedSettingView.setSelectItem(index: lastCyclesSelectIndex)
+            
+        }else{
+      
+            
+            if sender.tag == 1 { // 快慢速
+                speedSettingView.setSelectItem(index: lastSpeedSelectIndex)
+            } else if sender.tag == 2 { // 跳跃卡点
+                speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
+            } else if sender.tag == 3 { // 仅音乐
+                customSpeedSettingView.isJumpSpeedModel = false
+                speedSettingView.viewType = 2
+            }
+            
+           
         }
-        // 2 不同状的业务逻辑
+
+        // 2 设置 btn 不同显示状态
         var speedStuckBtnGifName = ""
         var jumpPointBtnGifName = ""
         if sender.tag == 1 { // 快慢速
             speedStuckBtnGifName = "speedstuck_h"
             jumpPointBtnGifName = "jumpPoint_n"
             currentCreateStickersModel = .createStickersModelSpeed
-            speedSettingView.setSelectItem(index: lastSpeedSelectIndex)
-         
-            
+        
         } else if sender.tag == 2 { // 跳跃卡点
             speedStuckBtnGifName = "speedstuck_n"
             jumpPointBtnGifName = "jumpPoint_h"
-            speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
             currentCreateStickersModel = .createStickersModelPoint
 
         } else if sender.tag == 3 { // 仅音乐
             speedStuckBtnGifName = "speedstuck_n"
             jumpPointBtnGifName = "jumpPoint_n"
             currentCreateStickersModel = .createStickersModelOnlyMusic
-
+       
         }
-        
+    
         settingPlayerView()
         speedStuckBtnGif.kf.setImage(with: URL(fileURLWithPath:  Bundle.init().BF_mainbundle().path(forResource:speedStuckBtnGifName , ofType: ".gif")!))
         jumpPointBtnGif.kf.setImage(with: URL(fileURLWithPath:  Bundle.init().BF_mainbundle().path(forResource: jumpPointBtnGifName  , ofType: ".gif")!))
@@ -1043,109 +1077,138 @@ extension PQStuckPointEditerController {
                     }
                 }
             }
-        }else if (model == .createStickersModelOnlyMusic || model == .createStickersModelSpeed){ //仅音乐
+        }else if (model == .createStickersModelOnlyMusic || model == .createStickersModelSpeed){ //仅音乐 和 跳跃卡点
             for section in sections {
                 if section.sectionType == "normal" {
 
                     BFLog(message: "stuckPoints count is \(finallyStuckPoints.count)")
-                    //一共裁剪的段数
-                    var totalClipNum:Int = 0
-                    for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
-                        if sticker.type == StickerType.VIDEO.rawValue {
-                            let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
-
-                            var i:Int = 0
-                            //一个视频切的的段落
-                            var oneVideoClipNum:Int = 0
-
-                            var realUsedMusicDuration = 0.0
-                            while realUsedMusicDuration <= CMTimeGetSeconds(asset.duration) {
-                                //快速段
-                                let LA = maxSpeed * (finallyStuckPoints[i+1] - finallyStuckPoints[i])
-                                realUsedMusicDuration = realUsedMusicDuration + Float64(LA)
-                                if(realUsedMusicDuration > CMTimeGetSeconds(asset.duration)){ break}
-                                oneVideoClipNum = oneVideoClipNum + 1
-                                //慢速段
-                                if(i + 2 >= finallyStuckPoints.count){
-                                    break
+                    
+                    // 第一种情况:全是图片,图片回环播放
+                    if section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "video").count == 0, section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials(type: "image").count > 0 {
+                        for (index, point) in finallyStuckPoints.enumerated() {
+                            let sticker: PQEditVisionTrackMaterialsModel = section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials()[index % section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials().count]
+                            BFLog(message: "stickerlocationPath sticker : \(sticker.locationPath)")
+                            let stickerjson = sticker.toJSONString(prettyPrint: false)
+
+                            let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
+                            if deepCopySticker!.type == StickerType.IMAGE.rawValue {
+                                if index + 1 < finallyStuckPoints.count {
+                                    deepCopySticker!.timelineIn = Float64("\(finallyStuckPoints[index])") ?? 0.0
+                                    
+                                    deepCopySticker!.timelineOut = Float64("\(finallyStuckPoints[index + 1])") ?? 0.0
+                                    if deepCopySticker != nil {
+                                        deepCopySticker?.generateDefaultValues()
+                                        stickers.append(deepCopySticker!)
+                                    }
                                 }
-                                let LB = minSpeed * (finallyStuckPoints[i+2] - finallyStuckPoints[i+1])
-                                realUsedMusicDuration = realUsedMusicDuration + Float64(LB)
-                                oneVideoClipNum = oneVideoClipNum + 1
-                                i = i + 1
                             }
-                            BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(oneVideoClipNum)")
-                            var lastOutTime:Float64 = 0.0
-                            for clipindex in 0 ... oneVideoClipNum - 1 {
-                                // deep copy sticker model 防止只有一个对象
-                                let stickerjson = sticker.toJSONString(prettyPrint: false)
-                                let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
-                                // 设置循环模式和适配模式
-                                deepCopySticker?.generateDefaultValues()
-                                //当前分段的速度
-                                var tempSpeed:Float = 1.0
-                                if model == .createStickersModelSpeed{
-                                    tempSpeed = (totalClipNum + clipindex) % 2 == 0 ? maxSpeed : minSpeed
+                        }
+                    }else{
+                        //一共裁剪的段数
+                        var totalClipNum:Int = 0
+                        for sticker in section.sectionTimeline!.visionTrack!.getEnableVisionTrackMaterials() {
+                            if sticker.type == StickerType.VIDEO.rawValue {
+                                let asset: AVURLAsset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + sticker.locationPath), options: nil)
+
+                                var i:Int = 0
+                                //一个视频切的的段落
+                                var oneVideoClipNum:Int = 0
+
+                                var realUsedMusicDuration = 0.0
+                                while realUsedMusicDuration <= CMTimeGetSeconds(asset.duration) {
+                                    //快速段
+                                    let LA = maxSpeed * (finallyStuckPoints[i+1] - finallyStuckPoints[i])
+                                    realUsedMusicDuration = realUsedMusicDuration + Float64(LA)
+                                    if(realUsedMusicDuration > CMTimeGetSeconds(asset.duration)){ break}
+                                    oneVideoClipNum = oneVideoClipNum + 1
+                                    //慢速段
+                                    if(i + 2 >= finallyStuckPoints.count){
+                                        break
+                                    }
+                                    let LB = minSpeed * (finallyStuckPoints[i+2] - finallyStuckPoints[i+1])
+                                    realUsedMusicDuration = realUsedMusicDuration + Float64(LB)
+                                    oneVideoClipNum = oneVideoClipNum + 1
+                                    i = i + 1
                                 }
-                          
-                                if(totalClipNum + 1 + clipindex < finallyStuckPoints.count){
-                                    deepCopySticker?.speedRate = tempSpeed
-
-                                    //定义临时使用的变量
-                                    let tempModel_In = lastOutTime
-                                    let tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
-
-                                    let tempTimelineIn = Float64(finallyStuckPoints[totalClipNum + clipindex])
-                                    let timelineOut = Float64(finallyStuckPoints[totalClipNum + 1 + clipindex])
-
-                                    //处理最后一点视频素材不够卡点时长 e.g. 0.3 卡点时长0.5
-                                    if(tempOut > realUsedMusicDuration){
-                                        BFLog(message: "最后一点视频素材不够卡点时长 ")
-                                        //最后一点素材时长
-                                        let lastAssetDuration = realUsedMusicDuration - tempOut
-                                        let pointDuration = timelineOut -  tempTimelineIn
-                                        let needSpeed = lastAssetDuration / pointDuration
-                                        //当前卡点段为快速
-                                        if(tempSpeed >= 1){
-                                            if(needSpeed > 0.4 * Double(tempSpeed)){
-                                                deepCopySticker?.speedRate = tempSpeed
-                                            } else{
-                                                continue
-                                            }
-                                        }else{//当前卡点段为慢速
-                                            if(needSpeed > 0.4 * Double(tempSpeed) && needSpeed > 0.2){
-                                                deepCopySticker?.speedRate = tempSpeed
-                                            } else{
-                                                continue
+                                BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(oneVideoClipNum)")
+                                var lastOutTime:Float64 = 0.0
+                                for clipindex in 0 ... oneVideoClipNum - 1 {
+                                    // deep copy sticker model 防止只有一个对象
+                                    let stickerjson = sticker.toJSONString(prettyPrint: false)
+                                    let deepCopySticker = Mapper<PQEditVisionTrackMaterialsModel>().map(JSONString: stickerjson!)
+                                    // 设置循环模式和适配模式
+                                    deepCopySticker?.generateDefaultValues()
+                                    //当前分段的速度
+                                    var tempSpeed:Float = 1.0
+                                    if model == .createStickersModelSpeed{
+                                        tempSpeed = (totalClipNum + clipindex) % 2 == 0 ? maxSpeed : minSpeed
+                                    }
+                              
+                                    if(totalClipNum + 1 + clipindex < finallyStuckPoints.count){
+                                        deepCopySticker?.speedRate = tempSpeed
+
+                                        //定义临时使用的变量
+                                        let tempModel_In = lastOutTime
+                                        let tempOut = lastOutTime + Float64(tempSpeed) * Float64(finallyStuckPoints[totalClipNum + 1 + clipindex] - finallyStuckPoints[totalClipNum + clipindex])
+
+                                        let tempTimelineIn = Float64(finallyStuckPoints[totalClipNum + clipindex])
+                                        let timelineOut = Float64(finallyStuckPoints[totalClipNum + 1 + clipindex])
+
+                                        //处理最后一点视频素材不够卡点时长 e.g. 0.3 卡点时长0.5
+                                        if(tempOut > realUsedMusicDuration){
+                                            BFLog(message: "最后一点视频素材不够卡点时长 ")
+                                            //最后一点素材时长
+                                            let lastAssetDuration = realUsedMusicDuration - tempOut
+                                            let pointDuration = timelineOut -  tempTimelineIn
+                                            let needSpeed = lastAssetDuration / pointDuration
+                                            //当前卡点段为快速
+                                            if(tempSpeed >= 1){
+                                                if(needSpeed > 0.4 * Double(tempSpeed)){
+                                                    deepCopySticker?.speedRate = tempSpeed
+                                                } else{
+                                                    continue
+                                                }
+                                            }else{//当前卡点段为慢速
+                                                if(needSpeed > 0.4 * Double(tempSpeed) && needSpeed > 0.2){
+                                                    deepCopySticker?.speedRate = tempSpeed
+                                                } else{
+                                                    continue
+                                                }
                                             }
+
                                         }
 
-                                    }
+                                        deepCopySticker?.model_in = tempModel_In
+                                        deepCopySticker?.out = tempOut
 
-                                    deepCopySticker?.model_in = tempModel_In
-                                    deepCopySticker?.out = tempOut
+                                        deepCopySticker?.timelineIn = tempTimelineIn
+                                        deepCopySticker?.timelineOut = timelineOut
 
-                                    deepCopySticker?.timelineIn = tempTimelineIn
-                                    deepCopySticker?.timelineOut = timelineOut
+                                        lastOutTime =  deepCopySticker?.out ?? 0
 
-                                    lastOutTime =  deepCopySticker?.out ?? 0
+                                    }
+                                    BFLog(message: " 创建 sticker crilp is in \(String(format: "%.6f", deepCopySticker?.model_in ?? 0)) out  \(String(format: "%.6f", deepCopySticker?.out ?? 0)) ,分段素材时长:\(String(format: "%.6f", (deepCopySticker?.out ?? 0) - (deepCopySticker?.model_in ?? 0))) ,分段显示时长:\(String(format: "%.6f", (deepCopySticker?.timelineOut ?? 0) - (deepCopySticker?.timelineIn ?? 0))), 总时长\(CMTimeGetSeconds(asset.duration)) timelineIN: \(String(format: "%.6f", deepCopySticker?.timelineIn ?? 0)) timelineOUT:\(String(format: "%.6f", deepCopySticker?.timelineOut ?? 0)) speedRate:\(deepCopySticker?.speedRate ?? 0.0)")
 
-                                }
-                                BFLog(message: " 创建 sticker crilp is in \(String(format: "%.6f", deepCopySticker?.model_in ?? 0)) out  \(String(format: "%.6f", deepCopySticker?.out ?? 0)) ,分段素材时长:\(String(format: "%.6f", (deepCopySticker?.out ?? 0) - (deepCopySticker?.model_in ?? 0))) ,分段显示时长:\(String(format: "%.6f", (deepCopySticker?.timelineOut ?? 0) - (deepCopySticker?.timelineIn ?? 0))), 总时长\(CMTimeGetSeconds(asset.duration)) timelineIN: \(String(format: "%.6f", deepCopySticker?.timelineIn ?? 0)) timelineOUT:\(String(format: "%.6f", deepCopySticker?.timelineOut ?? 0)) speedRate:\(deepCopySticker?.speedRate ?? 0.0)")
+                                    if deepCopySticker != nil {
+                                        stickers.append(deepCopySticker!)
+                                    }
 
-                                if deepCopySticker != nil {
-                                    stickers.append(deepCopySticker!)
                                 }
-
+                                totalClipNum = totalClipNum + oneVideoClipNum - 1
+                            } else if sticker.type == StickerType.IMAGE.rawValue {
+                                if(totalClipNum + 1 >= finallyStuckPoints.count){
+                                    BFLog(message: "数据出现错误!!!查正")
+                                    break
+                                }
+                                sticker.generateDefaultValues()
+                                sticker.timelineIn = Float64(finallyStuckPoints[totalClipNum])
+                                sticker.timelineOut = Float64(finallyStuckPoints[totalClipNum + 1])
+                                totalClipNum = totalClipNum + 1
+                                stickers.append(sticker)
                             }
-                            totalClipNum = totalClipNum + oneVideoClipNum - 1
-                        } else if sticker.type == StickerType.IMAGE.rawValue {
-                            sticker.generateDefaultValues()
-                            sticker.timelineIn = Float64(finallyStuckPoints[totalClipNum])
-                            sticker.timelineOut = Float64(finallyStuckPoints[totalClipNum + 1])
-                            stickers.append(sticker)
                         }
                     }
+                   
                 }
             
             
@@ -1199,15 +1262,21 @@ extension PQStuckPointEditerController {
         for point in stuckPoints {
             BFLog(message: "没有 start end 计算后的卡点数\(point)")
         }
-        if stuckPoints.first != nil {
-            stuckPoints.removeFirst()
-        }
-        if stuckPoints.last != nil {
-            stuckPoints.removeLast()
+        //若音乐起点至第一个卡点点位之间时长t0<0.3时,此段时长与下一个点位时长合并,故第一段卡点部分时长为t0+d
+        if(Float(stuckPointMusicData?.startTime ?? 0) - (stuckPoints.first ?? 0.0) < 0.3){
+            if stuckPoints.first != nil {
+                stuckPoints.removeFirst()
+            }
         }
-        // 开始时间是服务器返回, 结果时间根据策略计算的
         stuckPoints.insert(Float(stuckPointMusicData?.startTime ?? 0), at: 0)
-        stuckPoints.insert(Float(stuckPointMusicData?.endTime ?? 0), at: stuckPoints.count)
+        
+
+//        if stuckPoints.last != nil {
+//            stuckPoints.removeLast()
+//        }
+        // 开始时间是服务器返回, 结果时间根据策略计算的
+//        stuckPoints.insert(Float(stuckPointMusicData?.startTime ?? 0), at: 0)
+//        stuckPoints.insert(Float(stuckPointMusicData?.endTime ?? 0), at: stuckPoints.count)
 
         for point in stuckPoints {
             BFLog(message: "有 start end 计算后的卡点数\(point)")
@@ -1231,10 +1300,6 @@ extension PQStuckPointEditerController {
         let stuckPointsTemp:Array<Float>
   
            
-        
-        if(selectedDataCount == selectedImageDataCount){
-        
-        }
         //最后真正要使用推荐结束时长
         var realUsedMusicDuration:Float = 0.0
         switch model {
@@ -1272,7 +1337,6 @@ extension PQStuckPointEditerController {
   
             break
         case .createStickersModelSpeed://快慢速
-//                (1:快节奏,2:适中,3:慢节奏)
 //          快慢速  (2:快节奏,3:适中,4:慢节奏)
             stuckPointsTemp  = getUsedStuckPoint(seed: (stuckPointMusicData?.speed ?? 0) + 1)
             
@@ -1292,7 +1356,7 @@ extension PQStuckPointEditerController {
             var i:Int = 0
             var LACount:Int = 0
             var LBCount:Int = 0
-            while realUsedMusicDuration <= Float(selectedTotalDuration) {
+            while realUsedMusicDuration < Float(selectedTotalDuration) && selectedTotalDuration != 0 {
             
                 //回环从头取
                 if(i+2 > stuckPointsTemp.count){
@@ -1367,8 +1431,62 @@ extension PQStuckPointEditerController {
             break
      
         }
+        //拼接图片所使用的时长
+        //二,最一个卡点在原数组中的位置,从这个位置开始拼接图片所要使用的卡点
+        var pointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
+            (point == (finallyStuckPoints.last ?? 0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+        })
+        pointIndex = (pointIndex ?? 0) + 1
+       
+        for i in 0...selectedImageDataCount {
+ 
+            finallyStuckPoints.append(stuckPointsTemp[(i + Int(pointIndex ?? 0))  % stuckPointsTemp.count] + Float((i + Int(pointIndex ?? 0)) / stuckPointsTemp.count) * (stuckPointsTemp.first ?? 0))
+        }
+        selectedTotalDuration = Float64(((finallyStuckPoints.last ?? 0) - (finallyStuckPoints.first ?? 0)))
+         
+         //3)素材全是图片时如果时长 < 10s要做轮播处理
+         if(selectedDataCount == selectedImageDataCount && selectedTotalDuration < 10 ){
+            //已经设置过循环次数
+            if(lastCyclesSelectIndex != 0){
+                for i in 0...lastCyclesSelectIndex {
+                    
+                    var pointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
+                        (point == (finallyStuckPoints.last ?? 0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+                    })
+                    pointIndex = (pointIndex ?? 0) + 1
+                    for i in 0...selectedImageDataCount {
+                        
+                        finallyStuckPoints.append(stuckPointsTemp[(i + Int(pointIndex ?? 0))  % stuckPointsTemp.count] + Float((i + Int(pointIndex ?? 0)) / stuckPointsTemp.count) * (stuckPointsTemp.first ?? 0))
+                    }
+                }
+            }else{
+                
+                lastCyclesSelectIndex = 0
+                while selectedTotalDuration < 10{
+                  
+                    //不够10S 时 一次加图片数量的卡点数
+                    var pointIndex = stuckPointsTemp.firstIndex(where: { (point) -> Bool in
+                        (point == (finallyStuckPoints.last ?? 0).truncatingRemainder(dividingBy: (stuckPointsTemp.last ?? 0)))
+                    })
+                    pointIndex = (pointIndex ?? 0) + 1
+                    for i in 0...selectedImageDataCount {
+                        
+                        finallyStuckPoints.append(stuckPointsTemp[(i + Int(pointIndex ?? 0))  % stuckPointsTemp.count] + Float((i + Int(pointIndex ?? 0)) / stuckPointsTemp.count) * (stuckPointsTemp.first ?? 0))
+                    }
+                    
+                    selectedTotalDuration = Float64((finallyStuckPoints.last ?? 0) - (finallyStuckPoints.first ?? 0))
+                    lastCyclesSelectIndex = lastCyclesSelectIndex + 1
+                }
+                speedSettingView.setSelectItem(index: lastCyclesSelectIndex)
+                
+            }
+           
+            
+         }
+        
         
-        //计算最后使用的音频时长, 如果不用拼接音频时长度是卡点的倒数第二位时间
+//        lastJumpSpeedSelectIndex = 6
+        //三,计算最后使用的音频时长, 如果不用拼接音频时长度是卡点的倒数第二位时间
         let asset = AVURLAsset(url: URL(fileURLWithPath: documensDirectory + (stuckPointMusicData?.localPath ?? "")), options: nil)
  
         //原推荐卡点的倒数第二位时间
@@ -1381,6 +1499,7 @@ extension PQStuckPointEditerController {
             
         }
         
+        
         playeTimeRange = CMTimeRange(start: CMTime(value: CMTimeValue( Float(stuckPointMusicData?.startTime ?? 0) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE), end: CMTime(value: CMTimeValue((Float(finallyStuckPoints.last ?? 0)) * Float(BASE_FILTER_TIMESCALE)), timescale: BASE_FILTER_TIMESCALE))
   
         // 更新裁剪时间条的的ui数据
@@ -1562,12 +1681,6 @@ extension PQStuckPointEditerController {
             return
         }
         createPorjectData()
-  
-        //0 先计算所有图片的总时长 = 平均卡点时长  * 图片个数 * 档位
-        let avgPoint:Float = (Float(stuckPointMusicData!.rhythmSdata[0].pointTimes.last ?? 0) - Float(stuckPointMusicData!.rhythmSdata[0].pointTimes.first ?? 0))  / Float(stuckPointMusicData!.rhythmSdata[0].pointTimes.count) /  Float(BASE_FILTER_TIMESCALE) * Float(stuckPointMusicData?.speed ?? 2)
-        
-        selectedTotalDuration = selectedTotalDuration + Float64(Float(selectedImageDataCount) * avgPoint)
-        
         BFLog(message: "界面编辑界面时参数 选择素材时长:\(selectedTotalDuration) 选择素材总数:\(selectedDataCount) 选择图片总数\(selectedImageDataCount)")
         
  
@@ -1631,7 +1744,7 @@ extension PQStuckPointEditerController {
  
             //默认进入跳跃卡点模式
             editModelClick(sender: jumpPointBtn)
-            speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
+//            speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
             
         }else{
            
@@ -1639,12 +1752,12 @@ extension PQStuckPointEditerController {
             if(selectedTotalDuration > 0 && selectedTotalDuration <= 144){
                 
                 editModelClick(sender: speedStuckBtn)
-                speedSettingView.setSelectItem(index: lastSpeedSelectIndex)
+//                speedSettingView.setSelectItem(index: lastSpeedSelectIndex)
      
             }else{
                 //默认进入卡点模式
                 editModelClick(sender: jumpPointBtn)
-                speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
+//                speedSettingView.setSelectItem(index: lastJumpSpeedSelectIndex)
         
             }
         }

+ 23 - 15
BFFramework/Classes/Stuckpoint/View/PQSpeedSettingView.swift

@@ -34,7 +34,7 @@ class PQSpeedSettingView: UIView {
     // 保存数据
     var datas: Array<PQSpeedTitleModel> = Array()
     var lastSelectModel: PQSpeedTitleModel?
-    // view 初化的类型 1, 快慢速度卡点  2,跳跃卡点
+    // view 初化的类型 1, 快慢速度卡点  2,跳跃卡点 ,3,循环设置
     var viewType: Int = 0 {
         didSet {
             titleCollectionView.snp.remakeConstraints { make in
@@ -64,8 +64,9 @@ class PQSpeedSettingView: UIView {
                 }
 
             } else {
+                var str:String = (viewType == 2) ? "跳跃" : "循环"
                 let tempTitle =
-                    ["循环1x",
+                    ["\(str)1x",
                      "2x",
                      "3x",
                      "4x",
@@ -96,20 +97,35 @@ class PQSpeedSettingView: UIView {
         fatalError("init(coder:) has not been implemented")
     }
     
+ 
+    
     //设置默认选择的
     ///
     /// - Parameter index: 第几位 从0 开始
     func setSelectItem(index:Int) {
-       
+       BFLog(message: "setSelectItem is \(index)")
         lastSelectModel?.isSelected = false
-        lastSelectModel = datas[index]
+        if(index > 4){
+            let model = PQSpeedTitleModel()
+            model.title = "\(index + 1)x"
+            model.maxSpeed = Float(index + 1)
+            datas.insert(model, at: 5)
+            lastSelectModel = datas[5]
+        }else{
+            lastSelectModel = datas[index]
+        }
         lastSelectModel?.isSelected = true
         titleCollectionView.reloadData()
  
         //发出回调,调用方走统一处理逻辑
         if selectSpeedCallBack != nil {
             BFLog(message: "选择的速度为 max: \(lastSelectModel?.maxSpeed ?? 0.0) min: \(lastSelectModel?.minSpeed ?? 0.0)")
-            selectSpeedCallBack!(lastSelectModel?.maxSpeed ?? 0.0, lastSelectModel?.minSpeed ?? 0.0,index)
+            if(lastSelectModel?.title == "自定义"){
+                selectSpeedCallBack!(-1,-1,index)
+            }else{
+                selectSpeedCallBack!(lastSelectModel?.maxSpeed ?? 0.0, lastSelectModel?.minSpeed ?? 0.0,index)
+            }
+ 
         }
     }
 }
@@ -128,16 +144,8 @@ extension PQSpeedSettingView: UICollectionViewDelegate, UICollectionViewDataSour
 
     func collectionView(_: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         BFLog(message: "选择了 \(String(describing: datas[indexPath.row]))")
-        lastSelectModel?.isSelected = false
-        datas[indexPath.row].isSelected = true
-        titleCollectionView.reloadData()
-
-        lastSelectModel = datas[indexPath.row]
-
-        if selectSpeedCallBack != nil {
-            BFLog(message: "选择的速度为 max: \(lastSelectModel?.maxSpeed ?? 0.0) min: \(lastSelectModel?.minSpeed ?? 0.0)")
-            selectSpeedCallBack!(lastSelectModel?.maxSpeed ?? 0.0, lastSelectModel?.minSpeed ?? 0.0,indexPath.row)
-        }
+        setSelectItem(index: indexPath.row)
+ 
     }
 
     func collectionView(_ collectionView: UICollectionView, layout _: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {