Quellcode durchsuchen

开发测试完毕

100Years vor 2 Wochen
Ursprung
Commit
8e01bd6a86

+ 8 - 2
AIRingtone/Business/TSAIPhotoVC/TSGeneralPicVC/TSGeneralPicVC.swift

@@ -127,13 +127,19 @@ class TSGeneralPicVC: TSBottomAlertVC {
     func creatImage() {
         //判断 vip
         if kPurchaseToolShared.kJudgeVipFreeType(vipFreeNumType: vipFreeNumType, vc: self){ return }
+        
+        var oldModel:TSActionInfoModel? = nil
+        if let model = self.infoModel ,model.actionStatus == .failed{
+            oldModel = model
+        }
+        
         if gennerateType == .poster {
             let operation:TSGeneratePosterOperation = TSGeneratePosterOperationQueue.shared.creatOperation(uuid: UUID().uuidString) 
             operation.$stateDatauPblished.receive(on: DispatchQueue.main).sink {[weak self]  (state,model) in
                 guard let self = self else { return }
                 self.upDateView(state: state, model: model)
             }.store(in: &cancellable)
-            operation.creatPoster(oldModel: self.infoModel, prompt: prompt, promptSort: promptSort)
+            operation.creatPoster(oldModel: oldModel, prompt: prompt, promptSort: promptSort)
 
         }else if gennerateType == .photo {
             let operation:TSGeneratePhotoOperation = TSGeneratePhotoOperationQueue.shared.creatOperation(uuid: UUID().uuidString) 
@@ -141,7 +147,7 @@ class TSGeneralPicVC: TSBottomAlertVC {
                 guard let self = self else { return }
                 self.upDateView(state: state, model: model)
             }.store(in: &cancellable)
-            operation.creatPhoto(oldModel: self.infoModel, prompt: prompt, promptSort: promptSort)
+            operation.creatPhoto(oldModel: oldModel, prompt: prompt, promptSort: promptSort)
         }
     }
 }

+ 0 - 18
AIRingtone/Business/TSAIRintoneVC/TSAIRintoneVC/TSAIRintoneVC.swift

@@ -178,7 +178,6 @@ extension TSAIRintoneVC: UICollectionViewDataSource ,UICollectionViewDelegate,UI
            let cell = cell as? TSAIRintoneHistoryCell
         {
             cell.setTargetVC(targetVC: self, indexPath: indexPath)
-//            cell.setRingBtn.addTarget(self, action: #selector(clickSetRingBtn(_ :)), for: .touchUpInside)
             if let model = itemModel as? TSActionInfoModel {
                 cell.model = model
                 cell.ringModel = nil
@@ -191,23 +190,6 @@ extension TSAIRintoneVC: UICollectionViewDataSource ,UICollectionViewDelegate,UI
         return cell
     }
 
-//    @objc func clickSetRingBtn(_ btn:TSUIExpandedTouchButton){
-//        let indexPath = btn.indexPath
-//        if let sectionModel = self.viewModel.modelList.safeObj(At: indexPath.section),
-//        let model = sectionModel.list.safeObj(At: indexPath.item){
-//            if let model = model as? TSActionInfoModel {
-//                _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: self, urlString: model.response.musicUrl, fileName: model.response.title)
-//            }else if let ringModel = model as? TSRingModel {
-//                _ = kPurchaseToolShared.kshareBand(needVip: ringModel.vip, vc: self, urlString: ringModel.audioUrl, fileName: ringModel.title){ success in
-//                    if success {
-//                        TSMineRintoneHistory.shared.saveModel(model: ringModel)
-//                    }
-//                }
-//            }
-//        }
-//        TSBusinessAudioPlayer.shared.stop()
-//    }
-    
     public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
     }
     

+ 9 - 32
AIRingtone/Business/TSAIRintoneVC/TSAIRintoneVC/View/TSAIRintoneHistoryCell.swift

@@ -230,14 +230,14 @@ extension TSAIRintoneHistoryCell {
     
 
     func changePlayerState(state:TSBusinessAudioPlayer.PlayerState){
-        if playSelf == false {
-            if ringView.isPlay == true ||
-                ringView.isloading == true
-            {
-                ringView.handelAudioPlayerStateChange(state: .stop)
-            }
-            return
-        }
+//        if playSelf == false {
+//            if ringView.isPlay == true ||
+//                ringView.isloading == true
+//            {
+//                ringView.handelAudioPlayerStateChange(state: .stop)
+//            }
+//            return
+//        }
 //        dePrint("changePlayerState = \(state)")
         ringView.handelAudioPlayerStateChange(state: state)
     }
@@ -298,22 +298,12 @@ extension TSAIRintoneHistoryCell {
 extension TSAIRintoneHistoryCell {
     
     @objc func clickSetRingBtn(){
-
-        guard let targetVC = targetVC else { return }
-
         if let model = model {
-//            _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: targetVC, urlString: model.response.musicUrl, fileName: model.response.title)
             setShareBand(infoModel: model)
         }else if let ringModel = ringModel  {
-//            _ = kPurchaseToolShared.kshareBand(needVip: ringModel.vip, vc: targetVC, urlString: ringModel.audioUrl, fileName: ringModel.title)
-//            { success in
-//                if success {
-//                    TSMineRintoneHistory.shared.saveModel(model: ringModel)
-//                }
-//            }
             setShareBand(ringModel: ringModel)
         }
-        
+    
         TSBusinessAudioPlayer.shared.stop()
     }
     
@@ -328,24 +318,11 @@ extension TSAIRintoneHistoryCell {
                 _ = kPurchaseToolShared.kshareBand(needVip: needVip, vc: targetVC, fileURL: path, fileName: fileName)
             }
         }
-        
-//        if let path = TSDownloadManager.getRingLocalURL(urlString: urlString) {
-//                _ = kPurchaseToolShared.kshareBand(needVip: needVip, vc: targetVC, fileURL: path, fileName: fileName)
-//            }else{
-//                TSRingLoadingView.shared.showWindow()
-//                _ = TSDownloadManager.downloadFile(urlString:urlString,missingEx: "mp3") { url, error in
-//                    if let path = url {
-//                        _ = kPurchaseToolShared.kshareBand(needVip: needVip, vc: targetVC, fileURL: path, fileName: fileName)
-//                    }
-//                    TSRingLoadingView.shared.remove()
-//                }
-//            }
     }
     
     func setShareBand(ringModel:TSRingModel){
         guard let targetVC = targetVC else { return }
         let needVip = ringModel.vip
-        let urlString = ringModel.audioUrl
         let fileName = ringModel.title
         
         let kshareBand:(URL)->Void = { path in

+ 0 - 4
AIRingtone/Business/TSAIRintoneVC/TSGeneralRintoneVC/TSGeneralRintoneVC+Event.swift

@@ -42,12 +42,8 @@ extension TSGeneralRintoneVC {
         updateInfoModel(model: model)
         switch state {
             case .failed(let errorStr):
-                audioPlayer.stop()
-//                hiddenSelfVC(hidden: false)
                 showError(text: errorStr)
             case .success:
-                audioPlayer.stop()
-//                hiddenSelfVC(hidden: false)
                 if let model = model {
                     showSuccess(model: model)
                 }else{

+ 31 - 25
AIRingtone/Business/TSAIRintoneVC/TSGeneralRintoneVC/TSGeneralRintoneVC.swift

@@ -110,32 +110,32 @@ class TSGeneralRintoneVC: TSBottomAlertVC {
             return
         }
         audioPlayer.stop()
-        
-//        if let path = TSDownloadManager.getRingLocalURL(urlString: model.ringtone) {
-//            _ = kPurchaseToolShared.kshareBand(needVip: getNeedVip, vc: self, fileURL: path, fileName:  model.name)
-//        }else{
-//            TSRingLoadingView.shared.showWindow()
-//            _ = TSDownloadManager.downloadFile(urlString:  model.ringtone,missingEx: "mp3") {[weak self] url, error in
-//                guard let self = self else { return }
-//                if let path = url {
-////                  let savePath = TSBusinessFileManager.saveRingPathURL.appendingPathComponent(path.lastPathComponent)
-////                  TSFileManagerTool.copyFileWithOverwrite(from: path, to: savePath)
-//                    _ = kPurchaseToolShared.kshareBand(needVip: getNeedVip, vc: self, fileURL: path, fileName:model.name)
-//                }
-//                
-//                TSRingLoadingView.shared.remove()
-//            }
-//        }
-        
-//        _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: self, urlString: model.response.musicUrl, fileName: model.response.title)
+        TSDownloadManager.getDownLoadRing(urlString: model.response.musicUrl){ url,downLoad in
+            if let path = url {
+                _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: self, fileURL: path, fileName: model.response.title)
+            }
+        }
     }
     
     @objc func clickPlay(){
-        if audioPlayer.isPlaying{
-            audioPlayer.stop()
-        }else{
-            audioPlayer.playUrlString( infoModel?.response.musicUrl)
+        
+        guard let infoModel = infoModel else { return }
+        
+        if  TSBusinessAudioPlayer.shared.isPlayURLString(string: infoModel.response.musicUrl) {
+            if TSBusinessAudioPlayer.shared.isLoading{
+                return
+            }
+            if TSBusinessAudioPlayer.shared.isPlaying{
+                TSBusinessAudioPlayer.shared.stop()
+            }else{
+                audioPlayer.playUrlString(infoModel.response.musicUrl)
+            }
+        }else {
+            TSBusinessAudioPlayer.shared.stop()//让上一个对象停止播放
+            ringView.monitorPlayStateDefaultHandle()//更换监听
+            audioPlayer.playUrlString(infoModel.response.musicUrl)
         }
+
     }
     
     override func viewWillDisappear(_ animated: Bool) {
@@ -157,18 +157,24 @@ class TSGeneralRintoneVC: TSBottomAlertVC {
         }else {
             creatRintone()
         }
-        ringView.monitorPlayStateDefaultHandle()
+    
     }
     
     func creatRintone() {
         if kPurchaseToolShared.kJudgeVipFreeType(vipFreeNumType: .ringtones, vc: self){ return }//判断 vip
         self.uuidString = UUID().uuidString
-        let operation:TSGenerateRintoneOperation = TSGenerateRintoneOperationQueue.shared.creatOperation(uuid: self.uuidString) as! TSGenerateRintoneOperation
+        let operation:TSGenerateRintoneOperation = TSGenerateRintoneOperationQueue.shared.creatOperation(uuid: self.uuidString) 
         operation.$stateDatauPblished.receive(on: DispatchQueue.main).sink {[weak self]  (state,model) in
             guard let self = self else { return }
             self.upDateView(state: state, model: model)
         }.store(in: &cancellable)
-        operation.creatRintone(oldModel: nil, prompt: prompt, promptSort: promptSort)
+        
+        var oldModel:TSActionInfoModel? = nil
+        if let model = self.infoModel ,model.actionStatus == .failed{
+            oldModel = model
+        }
+        
+        operation.creatRintone(oldModel: oldModel, prompt: prompt, promptSort: promptSort)
 //        operation.creatRintone(oldModel: self.infoModel, prompt: prompt, promptSort: promptSort)
     }
 }

+ 0 - 19
AIRingtone/Business/TSAIRintoneVC/TSGenerateHistoryVC/TSGenerateHistoryVC.swift

@@ -120,7 +120,6 @@ extension TSGenerateHistoryVC: UICollectionViewDataSource ,UICollectionViewDeleg
            let cell = cell as? TSAIRintoneHistoryCell
         {
             cell.setTargetVC(targetVC: self, indexPath: indexPath)
-//            cell.setRingBtn.addTarget(self, action: #selector(clickSetRingBtn(_ :)), for: .touchUpInside)
             if let model = itemModel as? TSActionInfoModel {
                 cell.model = model
                 cell.ringModel = nil
@@ -133,24 +132,6 @@ extension TSGenerateHistoryVC: UICollectionViewDataSource ,UICollectionViewDeleg
         return cell
     }
 
-//    @objc func clickSetRingBtn(_ btn:TSUIExpandedTouchButton){
-//        let indexPath = btn.indexPath
-//        if let sectionModel = self.viewModel.modelList.safeObj(At: indexPath.section),
-//        let model = sectionModel.list.safeObj(At: indexPath.item){
-//            if let model = model as? TSActionInfoModel {
-//                _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: self, urlString: model.response.musicUrl, fileName: model.response.title)
-//            }else if let ringModel = model as? TSRingModel {
-//                _ = kPurchaseToolShared.kshareBand(needVip: ringModel.vip, vc: self, urlString: ringModel.audioUrl, fileName: ringModel.title)
-////                { success in
-////                    if success {
-////                        TSMineRintoneHistory.shared.saveModel(model: ringModel)
-////                    }
-////                }
-//            }
-//        }
-//        TSBusinessAudioPlayer.shared.stop()
-//    }
-    
     public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         
     }

+ 0 - 19
AIRingtone/Business/TSDiscoverVC/TSDiscoverListVC/TSDiscoverListVC.swift

@@ -137,7 +137,6 @@ extension TSDiscoverListVC: UICollectionViewDataSource ,UICollectionViewDelegate
            let cell = cell as? TSAIRintoneHistoryCell
         {
             cell.setTargetVC(targetVC: self, indexPath: indexPath)
-//            cell.setRingBtn.addTarget(self, action: #selector(clickSetRingBtn(_ :)), for: .touchUpInside)
             if let model = itemModel as? TSActionInfoModel {
                 cell.model = model
                 cell.ringModel = nil
@@ -149,22 +148,4 @@ extension TSDiscoverListVC: UICollectionViewDataSource ,UICollectionViewDelegate
         
         return cell
     }
-
-//    @objc func clickSetRingBtn(_ btn:TSUIExpandedTouchButton){
-//        let indexPath = btn.indexPath
-//        if let sectionModel = self.viewModel.modelList.safeObj(At: indexPath.section),
-//        let itemModel = sectionModel.list.safeObj(At: indexPath.item){
-////            if let model = itemModel as? TSActionInfoModel {
-////                _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: self, urlString: model.response.musicUrl, fileName: model.response.title)
-////            }else
-//            if let ringModel = itemModel as? TSRingModel {
-//                _ = kPurchaseToolShared.kshareBand(needVip: ringModel.vip, vc: self, urlString: ringModel.audioUrl, fileName: ringModel.title){ success in
-//                    if success {
-//                        TSMineRintoneHistory.shared.saveModel(model: ringModel)
-//                    }
-//                }
-//            }
-//        }
-//        TSBusinessAudioPlayer.shared.stop()
-//    }
 }

+ 0 - 22
AIRingtone/Business/TSDiscoverVC/TSRingDownVC/TSRingDownVC.swift

@@ -124,7 +124,6 @@ extension TSRingDownVC: UICollectionViewDataSource ,UICollectionViewDelegate,UIC
            let cell = cell as? TSAIRintoneHistoryCell
         {
             cell.setTargetVC(targetVC: self, indexPath: indexPath)
-//            cell.setRingBtn.addTarget(self, action: #selector(clickSetRingBtn(_ :)), for: .touchUpInside)
             if let model = itemModel as? TSActionInfoModel {
                 cell.model = model
                 cell.ringModel = nil
@@ -137,27 +136,6 @@ extension TSRingDownVC: UICollectionViewDataSource ,UICollectionViewDelegate,UIC
         
         return cell
     }
-
-//    @objc func clickSetRingBtn(_ btn:TSUIExpandedTouchButton){
-//        let indexPath = btn.indexPath
-//        if let sectionModel = self.viewModel.modelList.safeObj(At: indexPath.section),
-//        let model = sectionModel.list.safeObj(At: indexPath.item){
-////            if let model = model as? TSActionInfoModel {
-////                _ = kPurchaseToolShared.kshareBand(needVip: model.response.vip, vc: self, urlString: model.response.musicUrl, fileName: model.response.title)
-////            }else
-//
-//            if let ringModel = model as? TSRingModel {
-//                _ = kPurchaseToolShared.kshareBand(needVip: ringModel.vip, vc: self, urlString: ringModel.audioUrl, fileName: ringModel.title)
-////                { success in
-////                    if success {
-////                        TSMineRintoneHistory.shared.saveModel(model: ringModel)
-////                    }
-////                }
-//            }
-//        }
-//        
-//        TSBusinessAudioPlayer.shared.stop()
-//    }
     
     public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         

+ 2 - 5
AIRingtone/Business/TSDiscoverVC/TSRingDownVC/VM/TSRingDownVM.swift

@@ -38,13 +38,10 @@ extension TSRingDownVM {
     }
     
     func removeModel(model:TSRingModel){
+        let removePath = model.documentPath.fillDocumentURL
         TSMineRintoneHistory.shared.removeModel(model: model)
         updateRecentData()
-        if let pathURL = TSDownloadManager.getRingLocalURL(ringModel: model) {
-//        if let pathURL = TSCommonTool.getCachedURLString(from: model.audioUrl) {
-            TSFileManagerTool.removeItem(from: pathURL)
-        }
-
+        TSFileManagerTool.removeItem(from: removePath)
     }
     
 }

+ 32 - 33
AIRingtone/Business/TSEditAudioVideoVC/TSEditAudioVideoBaseVC.swift

@@ -209,7 +209,7 @@ class TSEditAudioVideoBaseVC: TSBaseVC , ZHCroppedDelegate, ZHWaveformViewDelega
         dragRightView.isUserInteractionEnabled = true
         
         let gradientImageView = UIImageView.createImageView(imageName: "trackBg_gradient",contentMode: .scaleToFill)
-        trackContentView.addSubview(gradientImageView)
+        trackBgView.addSubview(gradientImageView)
         gradientImageView.snp.makeConstraints { make in
             make.leading.top.trailing.equalToSuperview()
             make.height.equalTo(trackViewH)
@@ -460,15 +460,20 @@ class TSEditAudioVideoBaseVC: TSBaseVC , ZHCroppedDelegate, ZHWaveformViewDelega
     }
     
     override func dealThings() {
+        
+        dePrint("TSEditAudioVideoBaseVC ringModel = \(String(describing: ringModel.toJSONString())),editOriginalURL = \(editOriginalURL)")
+        
+        if ringModel.duration == 0, player.duration != 0 {
+            ringModel.duration = Int(player.duration)
+        }
+        
         operationCache.append(ringModel)
         reloadTrackView()
     }
-    
-    
-    
+
     private lazy var player:TSBusinessAudioPlayer = {
         let player = TSBusinessAudioPlayer()
-        
+        player.loadLoactionURL(url: self.editOriginalURL)
         player.currentTimeChangedHandle = { [weak self] current,total in
             guard let self = self else { return }
             handlePlayer(progressChanged: current, total: total)
@@ -507,7 +512,7 @@ class TSEditAudioVideoBaseVC: TSBaseVC , ZHCroppedDelegate, ZHWaveformViewDelega
                 do {
                     try FileManager.default.removeItem(at: fileUrl)
                 } catch {
-                    dePrint("删除文件失败")
+                    dePrint("TSEditAudioVideoBaseVC 删除文件失败")
                 }
             }
         }
@@ -556,17 +561,12 @@ class TSEditAudioVideoBaseVC: TSBaseVC , ZHCroppedDelegate, ZHWaveformViewDelega
 //        undoButton.isEna bled = operationCache.count > 1
         cutButton.setBtnEnabled(isEnabled: false)
     }
-    
-    func setupUI() {
-        
-        
-    }
 
     override func navBarClickLeftAction() {
         TSCustomAlertController.show(in: self, config: TSCustomAlertController.AlertConfig(
             message: "As you leave, the changes you have made will be lost.".localized,
-            messageColor: .red,
-            messageFont: .systemFont(ofSize: 15, weight: .medium),
+            messageColor: .white,
+            messageFont: .systemFont(ofSize: 16),
             
             cancelTitle: "Leave".localized,
             cancelColor: .textAssist,
@@ -679,12 +679,12 @@ extension TSEditAudioVideoBaseVC {
 
     @objc private func leftPanRecognizer(sender: UIPanGestureRecognizer) {
         
-        dePrint("leftPanRecognizer=\(sender)")
+        dePrint("TSEditAudioVideoBaseVC leftPanRecognizer=\(sender)")
         let limitMinCenterX: CGFloat = startMinCenterX
         let limitMaxCenterX: CGFloat = startMaxCenterX
         guard limitMaxCenterX > limitMinCenterX else {
             if sender.state == .began {
-                dePrint("rightPanRecognizer No less than 10s")
+                dePrint("TSEditAudioVideoBaseVC rightPanRecognizer No less than 10s")
                 TSToastShared.showToast(text:"No less than 10s".localized)
             }
             return
@@ -733,12 +733,12 @@ extension TSEditAudioVideoBaseVC {
     
 
     @objc private func rightPanRecognizer(sender: UIPanGestureRecognizer) {
-        dePrint("rightPanRecognizer=\(sender)")
+        dePrint("TSEditAudioVideoBaseVC rightPanRecognizer=\(sender)")
         let limitMinCenterX: CGFloat = endMinCenterX
         let limitMaxCenterX: CGFloat = endMaxCenterX
         guard limitMaxCenterX > limitMinCenterX else {
             if sender.state == .began {
-                dePrint("rightPanRecognizer No less than 10s")
+                dePrint("TSEditAudioVideoBaseVC rightPanRecognizer No less than 10s")
                 // 越界,拖不动了
                 TSToastShared.showToast(text:"No less than 10s".localized)
             }
@@ -859,12 +859,20 @@ extension TSEditAudioVideoBaseVC {
     }
     
     func saveButtonClick() {
+        handleSaveCutAudio()
+    }
+    
+    
+    func handleSaveCutAudio(completion:((TSRingModel?)->Void)? = nil){
         player.pause()
         // 保存音频
         startCutAudio { result, errMsg,savePath in
             if let ringModel = result {
                 // 裁剪的音频,使用本地文件播放,清空网络url
+                dePrint("TSEditAudioVideoBaseVC saveModel ringModel = \(ringModel.toJSONString())")
                 TSMineRintoneHistory.shared.saveModel(model: ringModel)
+                
+                completion?(ringModel)
                 DispatchQueue.main.async {
                     self.pop()
                     if let window = WindowHelper.getKeyWindow() {
@@ -880,26 +888,16 @@ extension TSEditAudioVideoBaseVC {
                 DispatchQueue.main.async {
                     TSToastShared.showToast(text: errMsg ?? "Sorry, Save Failure".localized)
                 }
+                completion?(nil)
             }
         }
     }
     
     func setButtonClick() {
-        player.pause()
-        // 保存音频
-        startCutAudio { result, errMsg,savePath in
-            if let ringModel = result,let savePath = savePath {
-                // 裁剪的音频,使用本地文件播放,清空网络url
-                TSMineRintoneHistory.shared.saveModel(model: ringModel)
-                _ = kPurchaseToolShared.kshareBand(needVip: false, vc: self, fileURL:savePath, fileName: ringModel.title){ success in
-                    if success {
-                        TSMineRintoneHistory.shared.saveModel(model: ringModel)
-                    }
-                }
-            } else {
-                DispatchQueue.main.async {
-                    TSToastShared.showToast(text: errMsg ?? "Sorry, Save Failure".localized)
-                }
+        handleSaveCutAudio { model in
+            if let ringModel = model {
+                let path = ringModel.documentPath.fillDocumentURL
+                _ = kPurchaseToolShared.kshareBand(needVip: false, vc: self, fileURL: path, fileName: ringModel.title)
             }
         }
     }
@@ -913,7 +911,8 @@ extension TSEditAudioVideoBaseVC {
        
     
        let savePath = TSDownloadManager.generateRingSaveLocalURL(name: copyModel.title)
-
+        TSFileManagerTool.checkFolderAndCreate(from: savePath)
+        
         copyModel.duration = Int(endDuration - startDuration)
         TSRingLoadingView.shared.showWindow()
         audioTool.startTansformAudio(url:editOriginalURL.path, from: startDuration, to: endDuration, fadeIn: Double(fadeInDuration), fadeOut: Double(fadeOutDuration),addVolume: Double(outputVolume) ,savePath: savePath.path) { filePath, errMsg in

+ 4 - 14
AIRingtone/Business/TSThemeVC/TSThemeSetVC/TSThemeSetVC.swift

@@ -144,20 +144,10 @@ extension TSThemeSetVC {
         audioPlayer.stop()
 //        if kPurchaseToolShared.kJudgeVip(externalBool: getNeedVip, vc: self){ return }//判断 vip
         
-        
-        if let path = TSDownloadManager.getRingLocalURL(urlString: model.ringtone) {
-            _ = kPurchaseToolShared.kshareBand(needVip: getNeedVip, vc: self, fileURL: path, fileName:  model.name)
-        }else{
-            TSRingLoadingView.shared.showWindow()
-            _ = TSDownloadManager.downloadFile(urlString:  model.ringtone,missingEx: "mp3") {[weak self] url, error in
-                guard let self = self else { return }
-                if let path = url {
-//                  let savePath = TSBusinessFileManager.saveRingPathURL.appendingPathComponent(path.lastPathComponent)
-//                  TSFileManagerTool.copyFileWithOverwrite(from: path, to: savePath)
-                    _ = kPurchaseToolShared.kshareBand(needVip: getNeedVip, vc: self, fileURL: path, fileName:model.name)
-                }
-                
-                TSRingLoadingView.shared.remove()
+        TSDownloadManager.getDownLoadRing(urlString: model.ringtone){ [weak self] url,downLoad in
+            guard let self = self else { return }
+            if let path = url {
+                _ = kPurchaseToolShared.kshareBand(needVip:getNeedVip, vc: self, fileURL: path, fileName: model.ringtoneName)
             }
         }
         

+ 1 - 1
AIRingtone/Business/TSThemeVC/TSThemeVC/Model/TSThemeModel.swift

@@ -14,7 +14,7 @@ class TSThemeModel: TSBaseModel {
     var poster:String = ""//海报
     var themeId:String = ""
     var ringtone:String = ""//铃声
-    var ringtoneName:String = ""//铃声名
+    var ringtoneName:String = ""//铃声名
     var ringtoneCover:String = ""//铃声封面
     
     

+ 5 - 2
AIRingtone/Common/Tool/TSAudioPlayer/TSBusinessAudioPlayer.swift

@@ -102,6 +102,9 @@ class TSBusinessAudioPlayer {
         return false
     }
     
+    func loadLoactionURL(url:URL){
+        self.audioPlayer = TSAudioPlayer(url: url)
+    }
 
     func playUrlString(_ urlString:String?,localURL:URL? = nil,loop:Bool = false,indexPath:IndexPath? = nil) {
         self.stop()
@@ -270,13 +273,13 @@ extension TSBusinessAudioPlayer{
     static func getAudioFileInfo(path: String) -> AudioFileInfo? {
         // 1. 检查URL有效性
         guard let url = URL(string: path) else {
-            print("无效的URL字符串")
+            print("getAudioFileInfo 无效的URL字符串")
             return nil
         }
         
         // 2. 检查文件是否存在(仅限本地文件)
         guard FileManager.default.fileExists(atPath: url.path) else {
-            print("文件不存在或不是本地路径")
+            print("getAudioFileInfo 文件不存在或不是本地路径")
             return nil
         }
         

+ 20 - 7
AIRingtone/Common/Tool/TSBandRingTool/AudioTool.swift

@@ -48,25 +48,38 @@ class AudioTool {
 //        let command = "-i \(inPath) -vn -ss \(startDuration) -to \(endDuration) -c:a libmp3lame \(outPath)"
 //        let command1 = "-i \(inPath) -vn -ss \(startDuration) -to \(endDuration) -filter:a \"volume=2.0\" -c:a libmp3lame \(outPath)"
 
+        // 1. 计算裁剪后的音频时长(秒)
+        let startSec = startDuration
+        let endSec = endDuration
+        let segmentDuration = endSec - startSec  // 例如:30-10=20秒
         
-        // 计算淡出开始时间(总时长 - 淡出时长)
-        let fadeOutStartTime = endDuration - fadeOut
+        // 2. 计算淡出开始时间(裁剪后的最后 fadeOutDuration 秒
+        let fadeOutStartTime = segmentDuration - fadeOut // 20-5=15秒
         
+        // 3. 构建正确的 FFmpeg 命令(关键:-ss 和 -to 必须在 -i 之前!)
         let command = """
-        -i \(inPath) -vn -ss \(startDuration) -to \(endDuration) \
-        -filter:a "volume=\(addVolume), afade=t=in:ss=\(startDuration):d=\(fadeIn), afade=t=out:st=\(fadeOutStartTime):d=\(fadeOut)" \
+        -y -ss \(startDuration) -to \(endDuration) -i \(inPath) -vn \
+        -af "afade=in:st=0:d=\(fadeIn), afade=out:st=\(fadeOutStartTime):d=\(fadeOut), volume=\(addVolume)" \
         -c:a libmp3lame \(outPath)
         """
         
+        dePrint("执行命令:\n\(command)")
+        
         FFmpegKit.executeAsync(command) { session in
+            guard let session = session else { return }
 
-            let state = session?.getState()
-
+            if ReturnCode.isSuccess(session.getReturnCode()) {
+                dePrint("FFmpegKit ✅ 处理成功")
+            } else {
+                dePrint("FFmpegKit ❌ 处理失败。错误码:\(session.getReturnCode())")
+            }
+            
+            let state = session.getState()
             switch state {
             case .completed:
                 completionHandler(outputFilePath, nil)
             case .failed:
-                if let error = session?.getFailStackTrace() {
+                if let error = session.getFailStackTrace() {
                     completionHandler(nil, "Sorry, Extract Audio Failure".localized)
                 } else {
                     completionHandler(nil, "Sorry, Extract Audio Failure".localized)