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
5c34b7eff8

+ 36 - 14
BFRecordScreenKit/Classes/RecordScreen/View/BFChooseMusicView.swift

@@ -27,23 +27,35 @@ class BFChooseMusicView: UIView {
     var musicDic = [Int64 : [PQVoiceModel]]()
     
     var searchModel : PQVoiceModel?{
+        willSet{
+            if searchModel != nil {
+                if let catogory = categories.first(where: { mod in
+                    mod.tagName == "热门"
+                }){
+                    if let tid = catogory.tagId, let _ = musicDic[tid] {
+                        // 找到热门的数组
+                        musicDic[tid]?.removeFirst()
+                    }
+                }
+            }
+        }
         didSet {
             if let searchModel = searchModel {
                 if let catogory = categories.first(where: { mod in
                     mod.tagName == "热门"
                 }){
-                    if let tid = catogory.tagId {
+                    if let tid = catogory.tagId, let list = musicDic[tid] {
                         var arr = [PQVoiceModel]()
                         arr.append(searchModel)
-                        if let list = musicDic[tid]{
+                        if list.first?.musicId != searchModel.musicId {
                             arr.append(contentsOf: list)
+                            musicDic[tid] = arr
+                            searchModel.isSelected = true
+                            chosedMusic?.isSelected = false
+                            chosedMusic = searchModel
+                            
+                            musicTb.reloadData()
                         }
-                        musicDic[tid] = arr
-                        searchModel.isSelected = true
-                        chosedMusic?.isSelected = false
-                        chosedMusic = searchModel
-                        
-                        musicTb.reloadData()
                     }
                 }
             }
@@ -67,6 +79,8 @@ class BFChooseMusicView: UIView {
     
     var chosedIndexPath : IndexPath?
     
+    var chosedCellStatu : BFMuicInfoCellState = .pause
+    
     var loadedTimeRangesObserver : NSKeyValueObservation?
 
     // 试听音乐
@@ -133,8 +147,9 @@ class BFChooseMusicView: UIView {
         backgroundColor = UIColor.clear
         
         let dismisBtn = UIButton()
+        dismisBtn.tag = 1004
         dismisBtn.frame = CGRect(x: 0, y: 0, width: width, height: 200)
-        dismisBtn.addTarget(self, action: #selector(dimiss), for: .touchUpInside)
+        dismisBtn.addTarget(self, action: #selector(btnAction(btn:)), for: .touchUpInside)
         addSubview(dismisBtn)
         
         let backV = UIView()
@@ -197,6 +212,13 @@ class BFChooseMusicView: UIView {
         addSubview(progressL)
         
         self.musicVolume = 0.2
+        
+        NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: player.currentItem, queue: .main) {[weak self] notice in
+            guard let wself = self else { return }
+            
+            wself.choseCell()?.status = .pause
+            wself.chosedCellStatu = .pause
+        }
 
         loadedTimeRangesObserver = player.observe(\AVPlayer.currentItem?.loadedTimeRanges, options: [.new, .initial]) { [weak self] (player, change) in
             
@@ -208,6 +230,7 @@ class BFChooseMusicView: UIView {
                     if (player.currentItem?.asset as? AVURLAsset)?.url.absoluteString ?? "b" == cell.data?.musicPath ?? "a" {
                         if cell.status != .playing{
                             cell.status = .playing
+                            wself.chosedCellStatu = .playing
                         }
                     }
                 }
@@ -336,7 +359,7 @@ class BFChooseMusicView: UIView {
         switch btn.tag{
         case 1001:
             clickBtnAction?(.cancle)
-        case 1002:
+        case 1002, 1004:
             clickBtnAction?(.sure)
         case 1003:
             clickBtnAction?(.search)
@@ -354,10 +377,7 @@ class BFChooseMusicView: UIView {
         player.pause()
         choseCell()?.changeSelected(false)
     }
-    
-    @objc func dimiss(){
-        clickBtnAction?(.sure)
-    }
+
 }
 
 extension BFChooseMusicView:UITableViewDelegate, UITableViewDataSource {
@@ -376,6 +396,7 @@ extension BFChooseMusicView:UITableViewDelegate, UITableViewDataSource {
             if cell.data?.isSelected ?? false {
                 chosedIndexPath = indexPath
                 chosedMusic = cell.data
+                cell.status = chosedCellStatu
             }else{
                 cell.status = .normal
             }
@@ -421,6 +442,7 @@ extension BFChooseMusicView:UITableViewDelegate, UITableViewDataSource {
                 player.pause()
                 cell.status = .pause
             }
+            chosedCellStatu = cell.status
         }
     }
     

+ 0 - 1
BFRecordScreenKit/Classes/RecordScreen/View/Cell/BFMuicInfoCell.swift

@@ -22,7 +22,6 @@ class BFMuicInfoCell: UITableViewCell {
             addData()
         }
     }
-
     
     var status : BFMuicInfoCellState = .normal {
         didSet {