Browse Source

预览页搜索音乐 icon状态修改

huzhiqiang 3 years ago
parent
commit
440138c4fb

+ 14 - 0
BFFramework/Classes/Stuckpoint/Controller/PQEditMusicSearchController.swift

@@ -167,6 +167,7 @@ class PQEditMusicSearchController: PQBaseViewController {
         }
     }
     
+    var avPlayerTimeObserver:Any?
     /// 播放音乐
     /// - Parameter itemData: <#itemData description#>
     func playStuckPointMusic(itemData: PQVoiceModel?, isClearCurrentMusic: Bool = false) {
@@ -178,6 +179,10 @@ class PQEditMusicSearchController: PQBaseViewController {
             avPlayer.pause()
             playerItem?.removeObserver(self, forKeyPath: "status")
             playerItem?.removeObserver(self, forKeyPath: "error")
+            if avPlayerTimeObserver != nil {
+                avPlayer.removeTimeObserver(avPlayerTimeObserver as Any)
+            }
+            
             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))
@@ -187,6 +192,15 @@ class PQEditMusicSearchController: PQBaseViewController {
             playerItem?.addObserver(self, forKeyPath: "error", options: .new, context: nil)
             avPlayer.seek(to: CMTime(value: CMTimeValue((itemData?.startTime ?? 0) * playerTimescale), timescale: CMTimeScale(playerTimescale)))
             avPlayer.play()
+            
+            avPlayerTimeObserver = avPlayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 10), queue: DispatchQueue.global()) {[weak self] time in
+                if fabs(CMTimeGetSeconds(time) - (itemData?.startTime ?? 0)) > 0.1 {
+                    self?.avPlayer.removeTimeObserver(self?.avPlayerTimeObserver as Any)
+                    self?.avPlayerTimeObserver = nil
+                    // 停止cell loading动画
+                    PQNotification.post(name: NSNotification.Name(rawValue: "MusicContentCellIconLoadingAnimationStop"), object: nil)
+                }
+            }
 //            let player = TXVodPlayer()
 //            let config = TXVodPlayConfig()
 //            config.cacheFolderPath = videoCacheDirectory

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

@@ -1142,7 +1142,7 @@ extension PQStuckPointEditerController {
                 let clipNum = Int(max(round(Double(kongduan) * CMTimeGetSeconds(asset.duration) / videoTotalDuration), 1))
                 sticker.duration = CMTimeGetSeconds(asset.duration)
                 BFLog(message: "单个视频\(sticker.locationPath)时长::\(CMTimeGetSeconds(asset.duration)) ,clipNum is:\(clipNum)")
-                for clipindex in 0 ... clipNum - 1 {
+                for clipindex in 0 ..< clipNum {
                     // deep copy sticker model 防止只有一个对象
                     let deepCopySticker:PQEditVisionTrackMaterialsModel? = sticker.copy() as? PQEditVisionTrackMaterialsModel
                               
@@ -1169,7 +1169,7 @@ extension PQStuckPointEditerController {
                 stickers.append(sticker)
             }
         }
-
+//        kongduan = clipNumTep
         return stickers
     }
 

+ 3 - 0
BFFramework/Classes/Stuckpoint/View/PQStuckPointMusicContentCell.swift

@@ -106,6 +106,9 @@ class PQStuckPointMusicContentCell: UICollectionViewCell {
     required init?(coder _: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
+    deinit {
+        PQNotification.removeObserver(self)
+    }
 
     var bgmData: Any? {
         didSet {