Kaynağa Gözat

预览页 选择音乐 icon变化

huzhiqiang 3 yıl önce
ebeveyn
işleme
1bc85a5a52

+ 5 - 2
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointEditerController.swift

@@ -254,9 +254,12 @@ class PQStuckPointEditerController: PQBaseViewController {
         musicEditBGView.musicSearchBtn.addTarget(self, action: #selector(musicSearchBtnClick(sender:)), for: .touchUpInside)
 
         musicEditBGView.didSelectItemHandle = { [weak self] status in
-            self?.playerView.pause()
             if status == .isSelected{
-                self?.playerView.RenderViewOnclick()
+                if self?.playerView.status != .playing{
+                    self?.playerView.RenderViewOnclick()
+                }
+            }else{
+                self?.playerView.pause()
             }
         }
         musicEditBGView.btnClickHandle = { [weak self] _, bgmData in

+ 1 - 0
BFFramework/Classes/Stuckpoint/Controller/PQStuckPointMusicController.swift

@@ -395,6 +395,7 @@ class PQStuckPointMusicController: PQBaseViewController {
             if musicInfo.count > 0, isHotPage, isRefresh {
                 self?.hotList = musicInfo
                 self?.searchController.hotList = self?.hotList ?? []
+                self?.searchController.configMusicListData(isResetData: false, isRefresh: true, musicListData: musicInfo)
             }
         }
     }

+ 28 - 13
BFFramework/Classes/Stuckpoint/View/PQSelecteMusicView.swift

@@ -277,6 +277,14 @@ class PQSelecteMusicView: UIView {
             avPlayer.pause()
             playerItem?.removeObserver(self, forKeyPath: "status")
             playerItem?.removeObserver(self, forKeyPath: "error")
+            
+            if itemData!.musicId == currentPlayingInVideoData?.musicId {
+                itemData?.voiceStatue = .isSelected
+                currentPlayData = itemData
+                playerItem = nil
+                return
+            }
+            
             playerItem = AVPlayerItem(url: URL(string: itemData?.musicPath ?? "")!)
             if (itemData?.endTime ?? 0) > 0, (itemData?.endTime ?? 0) > (itemData?.startTime ?? 0) {
                 playerItem?.forwardPlaybackEndTime = CMTime(value: CMTimeValue((itemData?.endTime ?? 0) * playerTimescale), timescale: CMTimeScale(playerTimescale))
@@ -290,11 +298,12 @@ class PQSelecteMusicView: UIView {
 
             currentPlayData = itemData
         } else if itemData != nil, avPlayer.rate == 0.0 {
-            avPlayer.play()
-            itemData?.voiceStatue = .isPlaying
+            if itemData?.musicId != currentPlayingInVideoData?.musicId {
+                avPlayer.play()
+                itemData?.voiceStatue = .isPlaying
+            }
         } else {
             avPlayer.pause()
-     
             itemData?.voiceStatue = .isPause
       
         }
@@ -350,11 +359,15 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
 
             let itemData: Any = musicDatas[indexPath.item]
             let cell = collectionView.dequeueReusableCell(withReuseIdentifier: String(describing: PQSelectMusicCell.self), for: indexPath) as! PQSelectMusicCell
+            if (currentPlayingInVideoData?.musicId != nil && currentPlayingInVideoData?.musicId == (itemData as? PQVoiceModel)?.musicId){
+                (itemData as? PQVoiceModel)?.voiceStatue = .isSelected
+            }
             cell.bgmData = itemData as? PQVoiceModel
             cell.btnClickHandle = { [weak self] sender, bgmData in
                 
                 //暂停播放音乐
                 self?.pausePlayer()
+                self?.currentPlayingInVideoData?.voiceStatue = .isNormal
                 self?.currentPlayingInVideoData = bgmData as? PQVoiceModel
                 PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_musicSelect, pageSource: .sp_shanyinApp_main, extParams: ["musicName":(bgmData as? PQVoiceModel)?.musicName ?? "" ,"musicId":(bgmData as? PQVoiceModel)?.musicId ?? ""], remindmsg: "")
                 
@@ -407,19 +420,21 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
             }
             let music = musicDatas[indexPath.item]
             music.voiceStatue = .isSelected
-            if music.musicId != currentPlayingInVideoData?.musicId{
-                playStuckPointMusic(itemData:music)
-            }
-            selectMusicCollection.reloadData()
+//            if music.musicId != currentPlayingInVideoData?.musicId{
+            playStuckPointMusic(itemData:music)
+//            }else{
+//                avPlayer.pause()
+//            }
             PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonClick, objectType: .ot_shanyinApp_musicVideoPreview_musicCategorySelect, pageSource: .sp_shanyinApp_main, extParams: ["categoryName":currentSelectTag?.tagName ?? "","categoryId":currentSelectTag?.tagId ?? ""], remindmsg: "")
 
-            if music.musicId != currentPlayingInVideoData?.musicId{
+//            if music.musicId != currentPlayingInVideoData?.musicId{
 //                BFLog(1, message: "预览:\(music.musicName) 当前:\(currentPlayingInVideoData?.musicName)")
-                if didSelectItemHandle != nil {
-                    didSelectItemHandle!(music.voiceStatue)
-                }
+//            }
+            if didSelectItemHandle != nil {
+                didSelectItemHandle!(music.voiceStatue)
             }
-            
+            selectMusicCollection.reloadData()
+
          
         }else{
             //停止分类列表的滑动。防止切换分类时 crash
@@ -443,7 +458,7 @@ extension PQSelecteMusicView: UICollectionViewDelegate, UICollectionViewDataSour
 
     func collectionView(_ collectionView: UICollectionView, willDisplay _: UICollectionViewCell, forItemAt indexPath: IndexPath) {
         
-        if (collectionView == selectMusicCollection ){
+        if (collectionView == selectMusicCollection && musicDatas.count > indexPath.item ){
             let music = musicDatas[indexPath.item]
             
             PQEventTrackViewModel.baseReportUpload(businessType: .bt_buttonView, objectType: .ot_shanyinApp_musicVideoPreview_musicView, pageSource: .sp_shanyinApp_main, extParams: ["musicName":music.musicName ?? "" ,"musicId":music.musicId ?? ""], remindmsg: "")

+ 2 - 6
BFFramework/Classes/Utils/PQCommonMethodUtil.swift

@@ -146,17 +146,13 @@ public func BFLog<T>( _ type : Int = 0, _ file:String = #file, _ line:Int = #lin
         BuglyLog.level(.warn, logs: msg)
     }
 #if DEBUG
+    let dateFmt = DateFormatter()
+    dateFmt.dateFormat = "HH:mm:ss:SSSS"
      if type == 1 {
-        let dateFmt = DateFormatter()
-        dateFmt.dateFormat = "HH:mm:ss:SSSS"
         print("hhz-\(dateFmt.string(from: Date())) \(msg)");
      }else if type == 2 {
-        let dateFmt = DateFormatter()
-        dateFmt.dateFormat = "HH:mm:ss:SSSS"
         print("ak-\(dateFmt.string(from: Date())) \(msg)");
      }else if type == 3 {
-        let dateFmt = DateFormatter()
-        dateFmt.dateFormat = "HH:mm:ss:SSSS"
         print("ww-\(dateFmt.string(from: Date())) \(msg)");
      }