浏览代码

1,歌曲列表3个状态调整 2 , 搜索歌曲插入到热门第一个

jsonwang 3 年之前
父节点
当前提交
732fd6c511

+ 4 - 0
BFFramework/Classes/Stuckpoint/Model/PQVoiceModel.swift

@@ -13,6 +13,7 @@ public enum voiceStatue: Int {
     case isPlaying = 1 // 播放中
     case isNormal = 2 // 正常状态
     case isSelected = 3 // 选中状态,有红框 字红色 ,别的都没有
+    case isPause = 4 // 播放中
 }
 
 open class PQVoiceModel: NSObject, NSCopying {
@@ -82,6 +83,9 @@ open class PQVoiceModel: NSObject, NSCopying {
     public var rhythmMusicOut: Float64 = 0
     // 卡点视频-源项目ID(从那个项目做同款)
     public var originProjectId: String?
+    
+    //缓存使用的所在的分类 ID 不能用 tagsInfo 的 一首歌有可能在多个分类当中
+    public var cacheTagID:Int64?
     public func copy(with _: NSZone? = nil) -> Any {
         let voice = PQVoiceModel()
         voice.name = name

+ 60 - 25
BFFramework/Classes/Stuckpoint/View/PQSelecteMusicView.swift

@@ -38,8 +38,8 @@ class PQSelecteMusicView: UIView {
             BFLog(message: "AVPlayerItemDidPlayToEndTime = \(notify)")
             avPlayer.seek(to: CMTime(value: CMTimeValue((self?.currentPlayData?.startTime ?? 0) * 1000), timescale: CMTimeScale(playerTimescale)))
  
+            self?.currentPlayData?.voiceStatue = .isPause
 
-            self?.currentPlayData?.isPlaying = false
             self?.selectMusicCollection.reloadData()
         }
         PQNotification.addObserver(forName: .AVPlayerItemNewErrorLogEntry, object: avPlayer.currentItem, queue: .main) { notify in
@@ -124,13 +124,14 @@ class PQSelecteMusicView: UIView {
 
     //插入数据
     func insertSearchMusic(model:PQVoiceModel) {
-        model.isSelected = true
+      
+        model.voiceStatue = .isSelected
         searchMusiceDatas.insert(model, at: 0)
         
         //有搜索的数据
-//        if(musicDatas.first?.name == "热门"){
+        if(musicDatas.first?.cacheTagID == 425){
             musicDatas.insert(contentsOf: searchMusiceDatas, at: 0)
-//        }
+        }
         
         selectMusicCollection.reloadData()
     }
@@ -188,10 +189,10 @@ class PQSelecteMusicView: UIView {
                 self?.musicDatas = self!.musicDatas + musicInfo
                 
                 //有搜索的数据
-//                if((self?.searchMusiceDatas.count ?? 0) > 0 && self!.musicDatas.first?.name == "热门"){
+                if((self?.searchMusiceDatas.count ?? 0) > 0 && self!.musicDatas.first?.cacheTagID == 425){
                     self?.musicDatas.insert(contentsOf: self?.searchMusiceDatas ?? Array.init(), at: 0)
                    
-//                }
+                }
                 
                 self?.selectMusicCollection.reloadData()
             }
@@ -219,15 +220,16 @@ class PQSelecteMusicView: UIView {
             playerItem?.addObserver(self, forKeyPath: "error", options: .new, context: nil)
             avPlayer.seek(to: CMTime(value: CMTimeValue((itemData?.startTime ?? 0) * playerTimescale), timescale: CMTimeScale(playerTimescale)))
             avPlayer.play()
-            itemData?.isPlaying = true
+            itemData?.voiceStatue = .isPlaying
 
             currentPlayData = itemData
         } else if itemData != nil, avPlayer.rate == 0.0 {
             avPlayer.play()
-            itemData?.isPlaying = true
+            itemData?.voiceStatue = .isPlaying
         } else {
             avPlayer.pause()
-            itemData?.isPlaying = false
+     
+            itemData?.voiceStatue = .isPause
       
         }
         if isClearCurrentMusic {
@@ -239,7 +241,7 @@ class PQSelecteMusicView: UIView {
     //暂停播放音乐 并刷新 UI
     func pausePlayer() {
         avPlayer.pause()
-        currentPlayData?.isPlaying = false
+        currentPlayData?.voiceStatue = .isPause
         selectMusicCollection.reloadData()
     }
    
@@ -290,6 +292,14 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
                     self?.btnClickHandle!(sender, bgmData)
                     
                 }
+                
+                let musicIndex = self?.musicDatas.firstIndex(where: { (music) -> Bool in
+                    (music.musicId == (bgmData as? PQVoiceModel)?.musicId)
+                })
+                
+                self?.musicDatas[musicIndex ?? 0].voiceStatue = .isSelected
+
+                self?.selectMusicCollection.reloadData()
             }
             
             //自动请求下一页数据
@@ -321,17 +331,18 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
         //歌曲列表
         if (collectionView == selectMusicCollection ){
             musicDatas.forEach { item in
-                item.isSelected = false
+
+                item.voiceStatue = .isNormal
             }
             let music = musicDatas[indexPath.item]
-            music.isSelected = true
+            music.voiceStatue = .isSelected
             playStuckPointMusic(itemData:music)
             selectMusicCollection.reloadData()
             
             PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_musicCategorySelect, pageSource: .sp_shanyinApp_main, extParams: ["categoryName":music.tagsInfo?.tagName,"categoryId":music.tagsInfo?.tagId], remindmsg: "")
 
             if didSelectItemHandle != nil {
-                didSelectItemHandle!(music.isPlaying)
+                didSelectItemHandle!(music.voiceStatue == .isPlaying)
             }
          
         }else{
@@ -359,7 +370,7 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
             let music = musicDatas[indexPath.item]
             
             PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_musicView, pageSource: .sp_shanyinApp_main, extParams: ["musicName":music.musicName ?? "" ,"musicId":music.musicId ?? ""], remindmsg: "")
-        } 
+        }
     }
 }
 
@@ -504,26 +515,50 @@ class PQSelectMusicCell: UICollectionViewCell {
         
         musicNameLab.text = bgmData?.musicName ?? ""
         
-        if bgmData?.isSelected ?? false {
+        if  bgmData?.voiceStatue == .isSelected{
             playImageView.isHidden = false
-            if bgmData?.isPlaying ?? false {
-                playImageView.image = nil
-                playImageView.kf.setImage(with: URL(fileURLWithPath: Bundle().BF_mainbundle().path(forResource: "stuckPoint_music_playing", ofType: ".gif")!))
-
-            } else {
-                playImageView.image = UIImage().BF_Image(named: "stuckPoint_music_pause")
-            }
             imageMaskView.isHidden = false
-        } else {
+            playImageView.image = UIImage().BF_Image(named: "stuckPoint_music_selected")
+    
+        } else if  bgmData?.voiceStatue == .isPlaying{
+            playImageView.isHidden = false
+            imageMaskView.isHidden = false
+            playImageView.image = nil
+            playImageView.kf.setImage(with: URL(fileURLWithPath: Bundle().BF_mainbundle().path(forResource: "stuckPoint_music_playing", ofType: ".gif")!))
+      
+        } else if  bgmData?.voiceStatue == .isPause{
+            playImageView.isHidden = false
+            imageMaskView.isHidden = false
+            playImageView.image = UIImage().BF_Image(named: "stuckPoint_music_pause")
+      
+        }else {
             playImageView.isHidden = true
             playImageView.image = nil
             
             imageMaskView.isHidden = true
         }
         
-        confirmBtn.isHidden = !(bgmData?.isSelected ?? false)
+//        if  bgmData?.voiceStatue == .isSelected{
+//            playImageView.isHidden = false
+//            imageMaskView.isHidden = false
+//            if bgmData?.voiceStatue == .isPlaying {
+//                playImageView.image = nil
+//                playImageView.kf.setImage(with: URL(fileURLWithPath: Bundle().BF_mainbundle().path(forResource: "stuckPoint_music_playing", ofType: ".gif")!))
+//
+//            } else {
+//                playImageView.image = UIImage().BF_Image(named: "stuckPoint_music_pause")
+//            }
+//
+//        } else {
+//            playImageView.isHidden = true
+//            playImageView.image = nil
+//
+//            imageMaskView.isHidden = true
+//        }
+        
+        confirmBtn.isHidden = !(bgmData?.voiceStatue == .isPause || bgmData?.voiceStatue == .isPlaying)
 
-        musicNameLab.textColor = (bgmData?.isSelected ?? false) ? UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue):  UIColor.hexColor(hexadecimal: "#959595")
+        musicNameLab.textColor = (bgmData?.voiceStatue == .isSelected) ? UIColor.hexColor(hexadecimal: PQBFConfig.shared.styleColor.rawValue):  UIColor.hexColor(hexadecimal: "#959595")
 
     }
 

+ 1 - 0
BFFramework/Classes/Stuckpoint/ViewModel/PQStuckPointViewModel.swift

@@ -87,6 +87,7 @@ public class PQStuckPointViewModel: NSObject {
             if tempArr != nil, (tempArr?.count ?? 0) > 0 {
                 for (_,dict) in tempArr!.enumerated() {
                     let tempMusic = PQVoiceModel(jsonDict: dict)
+                    tempMusic.cacheTagID = tagId
                     if tempMusic.rhythmSdata.count > 0 && (videoCount > 0 || imageCount > 0 ||  totalDuration > 0)  {
 //                        tempMusic.endTime = tempMusic.startTime + tempMusic.stuckPointCuttingTime(videoCount: videoCount, imageCount: imageCount, totalDuration: totalDuration)
                         BFLog(message: "music:\(tempMusic.musicName ?? ""),\(tempMusic.startTime),\(tempMusic.endTime)")