I am using QueuePlayer to play a list of songs and the songs are playing. My issue is that I am trying to track whenever the current item changes. I try adding an observer to the QueuePlayer, but this isn't working. The observing func isn't getting called. Any help would be appreciated
Observer
queuePlayer.currentItem?.addObserver(self, forKeyPath: "currentItem", options: [.new, .old], context: nil)
}
Listening for observer // Not getting called when item changes
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "currentItem" {
if let oldItem = change?[NSKeyValueChangeKey.oldKey] as? AVPlayerItem {
print("Old item : \(oldItem)")
}
if let newItem = change?[NSKeyValueChangeKey.newKey] as? AVPlayerItem {
print("New item : \(newItem)")
}
}
}