Pārlūkot izejas kodu

Merge branch 'dev' of https://git.yishihui.com/iOS/BFRecordScreenKit into dev
合并代码

jsonwang 3 gadi atpakaļ
vecāks
revīzija
b47636e4fd

+ 1 - 0
BFRecordScreenKit.podspec

@@ -47,6 +47,7 @@ TODO: Add long description of the pod here.
   s.dependency 'BFNetRequestKit'
   s.dependency 'BFMaterialKit'
   s.dependency 'BFMediaKit'
+  s.dependency "BFUploadKit"
   s.dependency 'BFUIKit'
   s.dependency 'GPUImage'
 end

+ 54 - 0
BFRecordScreenKit/Classes/RecordScreen/Controller/BFMusicManager.swift

@@ -0,0 +1,54 @@
+//
+//  BFMusicManager.swift
+//  BFRecordScreenKit
+//
+//  Created by Harry on 2022/3/4.
+//
+
+import Foundation
+import BFMediaKit
+import BFCommonKit
+import BFNetRequestKit
+import Alamofire
+
+
+class BFMusicManager {
+    
+    public class func downloadMusic(model: PQVoiceModel, complete:(@escaping () -> Void)) {
+//        BFNetRequestAdaptor.postRequestData(url: "", parames: [:], commonParams: commonParams(), encoding: JSONEncoding.default, isJsonEncodingNormal: true, timein)
+        if let path = model.musicPath, let url = URL(string: path) {
+            
+            let request = URLRequest(url: url)
+            let session = URLSession.shared
+            let downloadTask = session.downloadTask(with: request,
+                   completionHandler: { (location:URL?, response:URLResponse?, error:Error?)
+                    -> Void in
+                print("location:\(location)")
+                if let locationPath = location?.path {
+                    BFMusicManager.moveLocation(locationPath: locationPath, model:model)
+                }
+                
+                complete()
+            })
+            downloadTask.resume()
+        }
+        
+        
+    }
+    
+    fileprivate class func moveLocation(locationPath: String, model: PQVoiceModel) {
+        let fileManager = FileManager.default
+        let fileName = (model.musicPath! as NSString).lastPathComponent
+        let documnets = bgMusicDirectory + fileName + ".mp3"
+        createDirectory(path: bgMusicDirectory)
+        do {
+            try fileManager.moveItem(atPath: locationPath, toPath: documnets)
+            model.wavFilePath = documnets
+        } catch {
+            BFLog(1, message: "移动失败, \(error)")
+        }
+        print("new location:\(documnets)")
+
+    }
+
+}

+ 9 - 4
BFRecordScreenKit/Classes/RecordScreen/Controller/BFMusicSearchController.swift

@@ -112,14 +112,19 @@ extension BFMusicSearchController : UITableViewDelegate, UITableViewDataSource {
         if let cell = cell as? BFMusicInfoSearchCell{
             cell.data = searchResults[indexPath.row]
 
-            cell.useCallback = {[weak self] in
+            cell.useCallback = {[weak self, weak cell] in
                 guard let wself = self else { return }
-                wself.choseAction?(cell.data)
+                wself.player.pause()
+                cell?.status = .pause
+                wself.choseAction?(cell?.data)
                 wself.dismiss(animated: true, completion: nil)
             }
-            cell.cutCallBack = {[weak self] in
+            cell.cutCallBack = {[weak self, weak cell] in
                 guard let wself = self else { return }
-                if let data = cell.data {
+                wself.player.pause()
+                cell?.status = .pause
+                
+                if let data = cell?.data {
                     wself.dismiss(animated: true) {[weak self] in
                         guard let wself = self else { return }
                         wself.cutActionCallback?(data)

+ 52 - 29
BFRecordScreenKit/Classes/RecordScreen/Controller/BFRecordScreenController.swift

@@ -17,6 +17,7 @@ import Foundation
 import GPUImage
 import Photos
 import UIKit
+import BFUploadKit
 
 struct WithDrawModel {
     var type: Int // 0:拖动; 1:预览播放暂停 2: 录音结束  3: 删除录音
@@ -48,6 +49,7 @@ public class BFRecordScreenController: BFBaseViewController {
     public var nextActionHandle: (() -> Void)?
     public var closeActionHandle: (() -> Void)?
     public var changeItemHandle: ((_ index: Int) -> Void)?
+    public var cleanScreen: ((Bool) -> Void)?
     // 当前录制结束的上报
     public var recordEndHandle: ((_ currentRecord: PQVoiceModel?) -> Void)?
     // 字幕按钮点击上报
@@ -512,20 +514,13 @@ public class BFRecordScreenController: BFBaseViewController {
     }()
     
     lazy var choseMusicPanel: BFChooseMusicView = {
-        let vv = BFChooseMusicView(frame: CGRect(x: 0, y: cScreenHeigth, width: cScreenWidth, height: cScreenHeigth - 200))
+        let vv = BFChooseMusicView(frame: CGRect(x: 0, y: cScreenHeigth, width: cScreenWidth, height: cScreenHeigth))
         vv.clickBtnAction = { [weak self, weak vv] type in
             guard let wself = self else { return }
             
             var nextAction : ((Bool) -> Void)?
             if type == BFChooseMusicViewClickType.sure {
-                let model = vv?.chosedMusic
-                wself.bgmModel = model
-                if let title = model?.musicName {
-                    wself.addMusicBtn.setTitle(model?.musicName, for: .normal)
-                }else{
-                    wself.addMusicBtn.setTitle("选择音乐", for: .normal)
-                }
-                // 设置music为背景音乐
+                wself.hadChoosed(music: vv?.chosedMusic)
             }else if type == .cancle{
                 
             }else if type == .search{
@@ -537,10 +532,7 @@ public class BFRecordScreenController: BFBaseViewController {
                         vc.modalPresentationStyle = .fullScreen
                         vc.choseAction = {[weak self] voiceModel in
                             guard let wself = self else { return }
-                            wself.bgmModel = voiceModel
-//                            wself.dismiss(animated: true) {
-//                                
-//                            }
+                            wself.hadChoosed(music: voiceModel)
                         }
                         
                         vc.cutActionCallback = {[weak self] voiceModel in
@@ -556,14 +548,14 @@ public class BFRecordScreenController: BFBaseViewController {
             let hiddAnimation = {[weak self] in
                 guard let wself = self else { return }
                 
-                wself.choseMusicPanel.frame = CGRect(x: 0, y: cScreenHeigth, width: cScreenWidth, height: cScreenHeigth - 200)
+                wself.choseMusicPanel.frame = CGRect(x: 0, y: cScreenHeigth, width: cScreenWidth, height: cScreenHeigth)
                 
                 wself.soundSettingBtn.isHidden = false
                 wself.cameraFlipBtn.isHidden = false
                 wself.voiceSettingBtn.isHidden = false
                 wself.subtitleBtn.isHidden = false
                 wself.addMusicBtn.isHidden = false
-                
+                wself.cleanScreen?(false)
             }
             
             UIView.animate(withDuration: 0.25, animations: hiddAnimation, completion: nextAction)
@@ -574,7 +566,7 @@ public class BFRecordScreenController: BFBaseViewController {
             UIView.animate(withDuration: 0.25) {[weak self] in
                 guard let wself = self else { return }
                 
-                wself.choseMusicPanel.frame = CGRect(x: 0, y: cScreenHeigth, width: cScreenWidth, height: cScreenHeigth - 200)
+                wself.choseMusicPanel.frame = CGRect(x: 0, y: cScreenHeigth, width: cScreenWidth, height: cScreenHeigth)
                 
                 wself.soundSettingBtn.isHidden = false
                 wself.cameraFlipBtn.isHidden = false
@@ -790,11 +782,22 @@ public class BFRecordScreenController: BFBaseViewController {
     override public func viewDidLoad() {
         super.viewDidLoad()
         _ = disablePopGesture()
+<<<<<<< HEAD
+        
+        let path = Bundle.main.path(forResource: "11111", ofType: "mp3")
+        bgmModel = PQVoiceModel.init()
+        bgmModel?.wavFilePath = path
+        bgmModel?.startCMTime  = CMTime.init(value: 20 * 1000_000, timescale: 1000_000)
+        bgmModel?.endCMTime  = CMTime.init(value: 240 * 1000_000, timescale: 1000_000)
+        bgmModel?.volume = 100
+
+=======
    
         let doubleTapGes = UITapGestureRecognizer(target: self, action: #selector(doubleTapAction(tap:)))
         doubleTapGes.numberOfTapsRequired = 2
         doubleTapGes.numberOfTouchesRequired = 1
         view.addGestureRecognizer(doubleTapGes)
+>>>>>>> c2402d0b7d3837cbda505e6074eded08f1528888
         
         // 进入活跃状态
         PQNotification.addObserver(self, selector: #selector(didBecomeActive), name: UIApplication.didBecomeActiveNotification, object: nil)
@@ -1537,17 +1540,6 @@ public class BFRecordScreenController: BFBaseViewController {
       
     }
     
-    @objc func doubleTapAction(tap:UITapGestureRecognizer) {
-        if !(bottomeView.bounds.contains(tap.location(in: bottomeView))
-             || navHeadImageView!.bounds.contains(tap.location(in: navHeadImageView!))
-             || !voiceSettingView.isHidden
-             || !subtitleSettingView.isHidden
-             || !audioSettingView.isHidden
-             || recordBtn.isHidden){
-            cameraFlipAction()
-        }
-    }
-    
     @objc func cameraFlipAction() {
         if currMediaType == .Camera && !recordBtn.isHidden  {
             rscmanager.cameraFlip()
@@ -1561,11 +1553,11 @@ public class BFRecordScreenController: BFBaseViewController {
         voiceSettingBtn.isHidden = true
         subtitleBtn.isHidden = true
         addMusicBtn.isHidden = true
-        
+        cleanScreen?(true)
         UIView.animate(withDuration: 0.25) {[weak self] in
             guard let wself = self else { return }
             
-            wself.choseMusicPanel.frame = CGRect(x: 0, y: 210, width: cScreenWidth, height: cScreenHeigth - 200)
+            wself.choseMusicPanel.frame = CGRect(x: 0, y: 0, width: cScreenWidth, height: cScreenHeigth)
         }
     }
 
@@ -2641,6 +2633,32 @@ public class BFRecordScreenController: BFBaseViewController {
             imageRecordProgress(isRecord: true, progress: progress)
         }
     }
+    
+    func hadChoosed(music:PQVoiceModel?) {
+        bgmModel = music
+
+        if let model = music {
+            if let title = model.musicName {
+                addMusicBtn.setTitle(title, for: .normal)
+            }else{
+                addMusicBtn.setTitle("选择音乐", for: .normal)
+            }
+            // 设置music为背景音乐
+            hadDowonloadMusic(model: model)
+        }else {
+            BFLog(1, message: "无效音乐")
+        }
+    }
+    
+    func hadDowonloadMusic(model: PQVoiceModel) {
+        if let path = model.musicPath {
+            PQDownloadManager.downLoadFile(url: path) { musicUrl, err in
+                if err == nil, musicUrl != nil {
+                    model.wavFilePath = musicUrl
+                }
+            }
+        }
+    }
 }
 
 extension BFRecordScreenController: GPUImageMovieDelegate {
@@ -2682,6 +2700,11 @@ extension BFRecordScreenController: UICollectionViewDelegate, UICollectionViewDa
             cell = BFVideoCoverViewCell.gpuVideoViewCell(collectionView: collectionView, indexPath: indexPath)
         case .Camera:
             cell = BFCameraCoverViewCell.gpuCamraViewCell(collectionView: collectionView, indexPath: indexPath)
+            (cell as? BFCameraCoverViewCell)?.cameraFlip = {[weak self] in
+                guard let wself = self else { return }
+                
+                wself.cameraFlipAction()
+            }
         default:
             break
         }

+ 29 - 8
BFRecordScreenKit/Classes/RecordScreen/View/BFChooseMusicView.swift

@@ -100,12 +100,23 @@ class BFChooseMusicView: UIView {
     override init(frame: CGRect) {
         super.init(frame: frame)
         
-        backgroundColor = UIColor.black
-        layer.cornerRadius = 10
+        backgroundColor = UIColor.clear
+        
+        let dismisBtn = UIButton()
+        dismisBtn.frame = CGRect(x: 0, y: 0, width: width, height: 200)
+        dismisBtn.addTarget(self, action: #selector(dimiss), for: .touchUpInside)
+        addSubview(dismisBtn)
+        
+        let backV = UIView()
+        backV.backgroundColor = .black
+        backV.isUserInteractionEnabled = true
+        backV.layer.cornerRadius = 10
+        backV.frame =  CGRect(x: 0, y: 200, width: cScreenWidth, height: cScreenHeigth - 190)
+        addSubview(backV)
         
         let cancelBtn = UIButton()
         cancelBtn.tag = 1001
-        cancelBtn.frame = CGRect(x: 18, y: 17, width: 35, height: 24)
+        cancelBtn.frame = CGRect(x: 18, y: 227, width: 35, height: 24)
         cancelBtn.setTitle("取消", for: .normal)
         cancelBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#616161"), for: .normal)
         cancelBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .regular)
@@ -114,7 +125,7 @@ class BFChooseMusicView: UIView {
         
         let sureBtn = UIButton()
         sureBtn.tag = 1002
-        sureBtn.frame = CGRect(x: width - 35 - 18, y: 17, width: 35, height: 24)
+        sureBtn.frame = CGRect(x: width - 35 - 18, y: 227, width: 35, height: 24)
         sureBtn.setTitle("确定", for: .normal)
         sureBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#389AFF"), for: .normal)
         sureBtn.titleLabel?.font = UIFont.systemFont(ofSize: 17, weight: .regular)
@@ -123,7 +134,7 @@ class BFChooseMusicView: UIView {
         
         let line1 = UIView()
         line1.backgroundColor = UIColor.hexColor(hexadecimal: "#272727")
-        line1.frame = CGRect(x: 0, y: 50, width: width, height: 1)
+        line1.frame = CGRect(x: 0, y: 260, width: width, height: 1)
         addSubview(line1)
 
         categoryView.frame = CGRect(x: 0, y: line1.bottomY, width: width - 50, height: 40)
@@ -223,7 +234,6 @@ class BFChooseMusicView: UIView {
                 return
             }
             
-            
             if wself.musicArray[tagId] == nil {
                 wself.musicArray[tagId] = [PQVoiceModel]()
             }
@@ -273,6 +283,7 @@ class BFChooseMusicView: UIView {
     @objc func btnAction(btn:UIButton) {
         
         player.pause()
+        chosedCell?.status = .pause
         
         switch btn.tag{
         case 1001:
@@ -289,6 +300,16 @@ class BFChooseMusicView: UIView {
         
     }
     
+    // 取消选歌
+    func cancelChooseMusic() {
+        chosedMusic = nil
+        player.pause()
+        chosedCell?.changeSelected(false)
+    }
+    
+    @objc func dimiss(){
+        clickBtnAction?(.sure)
+    }
 }
 
 extension BFChooseMusicView:UITableViewDelegate, UITableViewDataSource {
@@ -384,11 +405,11 @@ extension BFChooseMusicView : UICollectionViewDelegate, UICollectionViewDataSour
             getMusicsForCategory(tagId: categories[categorySelectIndex].tagId ?? 0, pageNum: 1)
             
         }else {
-            // 取消选歌
-            chosedMusic = nil
+            cancelChooseMusic()
         }
     }
     
+    
 }
 
 extension BFChooseMusicView: BFFlowLayoutDelegate{

+ 11 - 0
BFRecordScreenKit/Classes/RecordScreen/View/Cell/BFCameraCoverViewCell.swift

@@ -11,12 +11,23 @@ import GPUImage
 open class BFCameraCoverViewCell: BFImageCoverViewCell {
     
     public var initCameraAfterData:(()->())?
+    public var cameraFlip:(() -> Void)?
     
     @objc public class func gpuCamraViewCell(collectionView: UICollectionView, indexPath: IndexPath) -> BFCameraCoverViewCell {
         let cell: BFCameraCoverViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: BFCameraCoverViewCell.self), for: indexPath) as! BFCameraCoverViewCell
+        
+        let doubleTapGes = UITapGestureRecognizer(target: cell, action: #selector(doubleTapAction(tap:)))
+        doubleTapGes.numberOfTapsRequired = 2
+        doubleTapGes.numberOfTouchesRequired = 1
+        cell.contentView.addGestureRecognizer(doubleTapGes)
+        
         return cell
     }
     
+    @objc func doubleTapAction(tap:UITapGestureRecognizer) {
+        cameraFlip?()
+    }
+    
     public override var recordItem: BFRecordItemModel? {
         didSet {
 //            addData()