ios - AV Player observer in Swift - message was received but not handled -
i'm trying implement observer av player in pure swift.
i'm getting error: message received not handled. because object argument in constructor of observer i'm using nil?
i've placed example code below.
thanks
player.addobserver(self, forkeypath: "status", options:nskeyvalueobservingoptions(), context: nil) player.addobserver(self, forkeypath: "playbackbufferempty", options:nskeyvalueobservingoptions(), context: nil) player.addobserver(self, forkeypath: "playbacklikelytokeepup", options:nskeyvalueobservingoptions(), context: nil) player.addobserver(self, forkeypath: "loadedtimeranges", options: nskeyvalueobservingoptions(), context: nil) private func deallocobservers(player: avplayer) { player.removeobserver(self, forkeypath: "status") player.removeobserver(self, forkeypath: "playbackbufferempty") player.removeobserver(self, forkeypath: "playbacklikelytokeepup") } //observer av play override func observevalue(forkeypath keypath: string?, of object: any?, change: [nskeyvaluechangekey : any]?, context: unsafemutablerawpointer?) { if keypath == "status" { print("change @ keypath = \(keypath) \(object)") } if keypath == "playbackbufferempty" { print("playbackbufferempty - change @ keypath = \(keypath) \(object)") } if keypath == "playbacklikelytokeepup" { print("change @ keypath = \(keypath) \(object)") } }
normally issue happens when registered observer deallocates , kvo event triggers after that. fixing need remove observers before object going deallocated.
in case, registered 4 kvo changes , removing 3. following kvo observer not removed anywhere , causing issue.
player.addobserver(self, forkeypath: "loadedtimeranges", options: nskeyvalueobservingoptions(), context: nil)
change deallocobservers:
method like:
private func deallocobservers(player: avplayer) { player.removeobserver(self, forkeypath: "status") player.removeobserver(self, forkeypath: "playbackbufferempty") player.removeobserver(self, forkeypath: "playbacklikelytokeepup") player.removeobserver(self, forkeypath: "loadedtimeranges") }
Comments
Post a Comment