|
@@ -34,26 +34,26 @@ class PQSelecteMusicView: UIView {
|
|
|
|
|
|
lazy var avPlayer: AVPlayer = {
|
|
|
let avPlayer = AVPlayer()
|
|
|
- PQNotification.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: avPlayer.currentItem, queue: .main) { [weak self] notify in
|
|
|
- BFLog(message: "AVPlayerItemDidPlayToEndTime = \(notify)")
|
|
|
- avPlayer.seek(to: CMTime(value: CMTimeValue((self?.currentPlayData?.startTime ?? 0) * 1000), timescale: CMTimeScale(playerTimescale)))
|
|
|
-
|
|
|
- self?.currentPlayData?.voiceStatue = .isPause
|
|
|
-
|
|
|
- self?.selectMusicCollection.reloadData()
|
|
|
- }
|
|
|
- PQNotification.addObserver(forName: .AVPlayerItemNewErrorLogEntry, object: avPlayer.currentItem, queue: .main) { notify in
|
|
|
- BFLog(message: "AVPlayerItemNewErrorLogEntry = \(notify)")
|
|
|
- }
|
|
|
- PQNotification.addObserver(forName: .AVPlayerItemFailedToPlayToEndTime, object: avPlayer.currentItem, queue: .main) { notify in
|
|
|
- BFLog(message: "AVPlayerItemFailedToPlayToEndTime = \(notify)")
|
|
|
- }
|
|
|
- PQNotification.addObserver(forName: .AVPlayerItemPlaybackStalled, object: avPlayer.currentItem, queue: .main) { notify in
|
|
|
- BFLog(message: "AVPlayerItemPlaybackStalled = \(notify)")
|
|
|
- }
|
|
|
- avPlayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: CMTimeScale(playerTimescale)), queue: .main) { [weak self] cmTime in
|
|
|
- BFLog(message: "addPeriodicTimeObserver = \(cmTime)")
|
|
|
- }
|
|
|
+// PQNotification.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: avPlayer.currentItem, queue: .main) { [weak self] notify in
|
|
|
+// BFLog(message: "AVPlayerItemDidPlayToEndTime = \(notify)")
|
|
|
+// avPlayer.seek(to: CMTime(value: CMTimeValue((self?.currentPlayData?.startTime ?? 0) * 1000), timescale: CMTimeScale(playerTimescale)))
|
|
|
+//
|
|
|
+// self?.currentPlayData?.voiceStatue = .isPause
|
|
|
+//
|
|
|
+// self?.selectMusicCollection.reloadData()
|
|
|
+// }
|
|
|
+// PQNotification.addObserver(forName: .AVPlayerItemNewErrorLogEntry, object: avPlayer.currentItem, queue: .main) { notify in
|
|
|
+// BFLog(message: "AVPlayerItemNewErrorLogEntry = \(notify)")
|
|
|
+// }
|
|
|
+// PQNotification.addObserver(forName: .AVPlayerItemFailedToPlayToEndTime, object: avPlayer.currentItem, queue: .main) { notify in
|
|
|
+// BFLog(message: "AVPlayerItemFailedToPlayToEndTime = \(notify)")
|
|
|
+// }
|
|
|
+// PQNotification.addObserver(forName: .AVPlayerItemPlaybackStalled, object: avPlayer.currentItem, queue: .main) { notify in
|
|
|
+// BFLog(message: "AVPlayerItemPlaybackStalled = \(notify)")
|
|
|
+// }
|
|
|
+// avPlayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: CMTimeScale(playerTimescale)), queue: .main) { [weak self] cmTime in
|
|
|
+// BFLog(message: "addPeriodicTimeObserver = \(cmTime)")
|
|
|
+// }
|
|
|
return avPlayer
|
|
|
}()
|
|
|
|
|
@@ -106,6 +106,15 @@ class PQSelecteMusicView: UIView {
|
|
|
|
|
|
return musicSearchBtn
|
|
|
}()
|
|
|
+
|
|
|
+ deinit {
|
|
|
+ PQNotification.removeObserver(self)
|
|
|
+ avPlayer.currentItem?.removeObserver(self, forKeyPath: "status")
|
|
|
+ avPlayer.currentItem?.removeObserver(self, forKeyPath: "error")
|
|
|
+ avPlayer.pause()
|
|
|
+ avPlayer.replaceCurrentItem(with: nil)
|
|
|
+ playerItem = nil
|
|
|
+ }
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
super.init(frame: frame)
|